|
Ahhhh, of course, sorry!
I'm using Visual Studio 2005 Beta 2... It's a grid that comes with .NET 2.0. It's VERY useful, much better than the old DataGrid IMHO.
|
|
|
|
|
Ahh I see... I have 2005 Beta 2 but am not willing to install it in my work environment. Until I get build a test env, I cannot provide any good help to ya.
Try these two methods though.
1.) Create a timer set to 100ms and have the timer_elasped event close the form. and start the timer inside your douleclick method. This would allow the method to complete and then run the close time. This is not a good way to do it, but probably the easiest.
2.) Create an event delegate to close the form. Inside the code for the control_click call the method this.Invoke(new delegatename(delegatemethod)); Then in the delegatemethod() call this.close; This is the thread safe way to run form methods on a click. Hit me back if you need realcode examples and I'll make some for ya
|
|
|
|
|
The timer would probably work but as you said, it's not a very good way of doing it.
The delegate doesn't work AFAIK, I receive this error:
Exception has been thrown by the target of an invocation.
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
The invoke calls the delegated method ASAP (before the HitTest did it's job I guess) and the same error (more or less) happens... I think I'll solve the problem in another way (adding a button comes to mind).
Thanks again for your help
|
|
|
|
|
My mistake, I should've used BeginInvoke instead of Invoke.
This line of code works perfect:
this.BeginInvoke(new MethodInvoker(this.Close));
Thanks again for your help!
|
|
|
|
|
I have an app with two dialogs, one opened by the second. With 2 monitors the 2nd dialog opens on the same monitor if I set it to open in a normal state. IF i have it set to open maximized it always opens on monitor1, regardless of which monitor the first is on. Is there a way to change this behavior.
|
|
|
|
|
You could possibly programatically set the dialog to open in coords of the second monitor first and then change the property to Maximized once the dialog has fully loaded.
|
|
|
|
|
I tried doing a programmatic maximize in the constructor, it didn't work. The form still opened maximized on monitor1. When I demaximized it the normal version was on monitor two, and manually maxing it left it on mon2 just like before.
|
|
|
|
|
You don't want to do it in the constructor because you don't want it to maximize until it has been fully created and painted.
|
|
|
|
|
Where should I move the call to then?
|
|
|
|
|
Try it in the form_load event. I'll toy with it a bit as well as I have dual monitors also.
|
|
|
|
|
Yes, this worked for me: (My second monitor is on the LEFT of the screen... if yours is on the right, you would have to move it to a coord PAST the first monitor)
<code>
private void Form2_Load(object sender, System.EventArgs e)
{
this.Left = -458;
this.WindowState = FormWindowState.Maximized;
}
</code>
|
|
|
|
|
I've got a tabcontrol with a number of databound textboxes on a tabpage
(Form1). I've got a button that the user clicks that opens a dialog (Form2)
and does a lookup from a database. The user makes a selection and chooses a
button wired dialog.ok to close the dialog (form2) and populate the fields on the tabcontrol (Form1). It all works except the textboxes don't retain the new data when I tab across to another tab page.
Code To Open Dialog (Form1)=========================
private void btnLmoLookup_Click(object sender, System.EventArgs e)
{
Form2 LmoLookup = new Form2();
LmoLookup.StartPosition = FormStartPosition.CenterParent;
if( LmoLookup.ShowDialog() == DialogResult.OK )
{
txtBoxDocName.Text = LmoLookup.docFullName;
}
LmoLookup.Dispose();
}
Code To Create Public Variable (Form2)======================
public string docFullName
{
get{return
this.dsExtPhysLookup1.Tables["tblExternalPhysicians"].Rows[this.listBox1.SelectedIndex]["docFullName"].ToString();}
}
|
|
|
|
|
What is a quick way to cast a string (consisting of a number) into an int variable? Isn't there some quick function build in somewhere?
|
|
|
|
|
Convert.ToInt32(string);
also Convert.ToInt16(string);
I would look at all of the methods that the Convert class provides, they will all come in handy
|
|
|
|
|
|
i think this should help
string s="3";
int i = Convert.ToInt32(s);
Leejo
|
|
|
|
|
I have a datagird and a checkbox web control within the datagrid, I am trying to step through each datagriditem and detect whether the checkbox is checked or not, however when testing this application, the checkbox always shows unchecked? I have bound the checked property to a column in the datagrid, and added a button shich will execute code to delete all lines whose checkbox is checked. Please Help!
|
|
|
|
|
Can you post a code snippet of how you are acquiring this task? It seems to me that once you store the object (CheckBox) in the datagrid all you need to do is simply pull the object back out and read/change its properties.
<code>
foreach(DataGridItem item in DataGrid.Items)
{
if(item is CheckBox)
{
CheckBox cb = (CheckBox)item;
cb.Checked = true;
}
}
</code>
-- modified at 13:15 Friday 7th October, 2005
|
|
|
|
|
This is what I have currently and is not working:
foreach(DataGridItem DataGridItem in DataGrid1.Items)
{
CheckBox Checkbox1 = (CheckBox)DataGridItem.Cells[0].Controls[1];
if(Checkbox1.Checked == true)
{
sCmd2.CommandType=CommandType.Text;
sCmd2.CommandText = "del_merge_segment " + Request.QueryString.Get("iQuoteId") + "," + Request.QueryString.Get("txtLineNumber");
}
|
|
|
|
|
I would be careful casting to a checkbox when not first check to make sure it is a checkbox you're looking for. Since you're using DataGridItem.Cells[0].Controls[1] I'm assuming that the checkbox is the second control in the datagriditem. What is the first control? Also, are you saying that Checkbox1.Check is always coming back true? One other thing: Is this a WinForm or a WebForm?
|
|
|
|
|
The checkbox is th only control in the datset, I changed .Controls[1] to [0]. This is a webform and when the page runs if a check a checkbox and step through my code the checked property of the box I checked is showing false which is why my delete command is never running. When I run the code now after making the above changes and check a box and then click delete I get an invalid cast exception for the following line of code:
CheckBox Checkbox1 = (CheckBox)DataGridItem.Cells[0].Controls[0];
Is their a better way to do this?
|
|
|
|
|
That is a good way to do it, but be sure to check for the checkbox first. Also, since this is a web form, you have to make sure the control posts back to the form. Set the checkbox's property (AutoPostBack = true).
Here is how you check to make sure it is a checkbox BEFORE you cast it so as not to receive any cast errors:
<br />
if(DataGridItem.Cells[0].Controls[0] is CheckBox)<br />
{<br />
CheckBox Checkbox1 = (CheckBox)DataGridItem.Cells[0].Controls[0];<br />
}<br />
This will make sure that you don't get an invalid cast exception. You may also have to bind the data to the datagrid on Check_Changed event of the checkbox after it posts back. I would try the autopost back first, then if that doesn't work use a DataGrid1.Databind() inside the CheckChenged event of the checkbox.
|
|
|
|
|
The autopostback did not work, as my textbox is in a template column in the datagrid, do I perform the following?
private void CheckBox1_CheckedChanged(object sender, System.EventArgs e)
{
DataGrid1.DataBind();
}
The checkbox is still showing as unchecked. Here is my complete code if this helps. Thanks!
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Collections.Specialized;
namespace DeleteMergeSegments
{
///
/// Summary description for WebForm1.
///
public class WebForm1 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected DeleteMergeSegments.segmentDS segmentDS1;
protected System.Web.UI.WebControls.Button Delete;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
sqlDataAdapter1.Fill(segmentDS1);
DataGrid1.DataBind();
int loop1;
// Load NameValueCollection object.
NameValueCollection coll=Request.QueryString;
// Get names of all keys into a string array.
String[] arr1 = coll.AllKeys;
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
String[] arr2 = coll.GetValues(arr1[loop1]);
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.segmentDS1 = new DeleteMergeSegments.segmentDS();
((System.ComponentModel.ISupportInitialize)(this.segmentDS1)).BeginInit();
this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
this.Delete.Click += new System.EventHandler(this.Delete_Click);
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "mergeSegment", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("iQuoteId", "iQuoteId"),
new System.Data.Common.DataColumnMapping("siLineNumber", "siLineNumber"),
new System.Data.Common.DataColumnMapping("chSegmentDesc", "chSegmentDesc"),
new System.Data.Common.DataColumnMapping("iMergeSegmentQty", "iMergeSegmentQty")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = @"DELETE FROM mergeSegment WHERE (iQuoteId = @Original_iQuoteId) AND (siLineNumber = @Original_siLineNumber) AND (chSegmentDesc = @Original_chSegmentDesc) AND (iMergeSegmentQty = @Original_iMergeSegmentQty OR @Original_iMergeSegmentQty IS NULL AND iMergeSegmentQty IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_iQuoteId", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "iQuoteId", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_siLineNumber", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "siLineNumber", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_chSegmentDesc", System.Data.SqlDbType.VarChar, 75, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "chSegmentDesc", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_iMergeSegmentQty", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "iMergeSegmentQty", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=QED_IT4;packet size=4096;user id=sa;password=157m0nd0;data source=" +
"Production1;persist security info=False;initial catalog=laaf_o";
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = @"INSERT INTO mergeSegment(iQuoteId, siLineNumber, chSegmentDesc, iMergeSegmentQty) VALUES (@iQuoteId, @siLineNumber, @chSegmentDesc, @iMergeSegmentQty); SELECT iQuoteId, siLineNumber, chSegmentDesc, iMergeSegmentQty FROM mergeSegment WHERE (iQuoteId = @iQuoteId) AND (siLineNumber = @siLineNumber)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@iQuoteId", System.Data.SqlDbType.Int, 4, "iQuoteId"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@siLineNumber", System.Data.SqlDbType.SmallInt, 2, "siLineNumber"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@chSegmentDesc", System.Data.SqlDbType.VarChar, 75, "chSegmentDesc"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@iMergeSegmentQty", System.Data.SqlDbType.Int, 4, "iMergeSegmentQty"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT iQuoteId, siLineNumber, chSegmentDesc, iMergeSegmentQty FROM mergeSegment " +
"WHERE (iQuoteId = 10153)";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE mergeSegment SET iQuoteId = @iQuoteId, siLineNumber = @siLineNumber, chSegmentDesc = @chSegmentDesc, iMergeSegmentQty = @iMergeSegmentQty WHERE (iQuoteId = @Original_iQuoteId) AND (siLineNumber = @Original_siLineNumber) AND (chSegmentDesc = @Original_chSegmentDesc) AND (iMergeSegmentQty = @Original_iMergeSegmentQty OR @Original_iMergeSegmentQty IS NULL AND iMergeSegmentQty IS NULL); SELECT iQuoteId, siLineNumber, chSegmentDesc, iMergeSegmentQty FROM mergeSegment WHERE (iQuoteId = @iQuoteId) AND (siLineNumber = @siLineNumber)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@iQuoteId", System.Data.SqlDbType.Int, 4, "iQuoteId"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@siLineNumber", System.Data.SqlDbType.SmallInt, 2, "siLineNumber"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@chSegmentDesc", System.Data.SqlDbType.VarChar, 75, "chSegmentDesc"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@iMergeSegmentQty", System.Data.SqlDbType.Int, 4, "iMergeSegmentQty"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_iQuoteId", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "iQuoteId", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_siLineNumber", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "siLineNumber", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_chSegmentDesc", System.Data.SqlDbType.VarChar, 75, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "chSegmentDesc", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_iMergeSegmentQty", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "iMergeSegmentQty", System.Data.DataRowVersion.Original, null));
//
// segmentDS1
//
this.segmentDS1.DataSetName = "segmentDS";
this.segmentDS1.Locale = new System.Globalization.CultureInfo("en-US");
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.segmentDS1)).EndInit();
}
#endregion
private void Delete_Click(object sender, System.EventArgs e)
{
SqlConnection sc2 = new SqlConnection("workstation id=QED_IT4;packet size=4096;user id=sa;password=157m0nd0;data source=Production1;persist security info=False;initial catalog=laaf_l");
sc2.Open();
SqlCommand sCmd2 = sc2.CreateCommand();
SqlDataAdapter sda2 = new SqlDataAdapter();
sda2.DeleteCommand = sCmd2;
foreach(DataGridItem DataGridItem in DataGrid1.Items)
{
if(DataGridItem.Cells[0].Controls[0] is CheckBox)
{
CheckBox Checkbox1 = (CheckBox)DataGridItem.Cells[0].Controls[0];
if(Checkbox1.Checked == true)
{
sCmd2.CommandType=CommandType.Text;
sCmd2.CommandText = "del_merge_segment " + Request.QueryString.Get("iQuoteId") + "," + Request.QueryString.Get("txtLineNumber");
}
}
}
SqlCommand sCmd3=sc2.CreateCommand();
SqlDataAdapter sda3 = new SqlDataAdapter();
sda3.UpdateCommand = sCmd3;
sCmd3.CommandType = CommandType.Text;
sCmd3.CommandText ="resequence_merge_lines " + Request.QueryString.Get("iQuoteId");
}
AND HERE IS THE HTML:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="DeleteMergeSegments.WebForm1" %>
<title>WebForm1
<asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 40px; POSITION: absolute; TOP: 72px" runat="server" width="880px" cellpadding="1" cellspacing="2" forecolor="Purple" backcolor="#D8D8E6" autogeneratecolumns="False" datamember="mergeSegment" datasource="<%# segmentDS1 %>" borderstyle="Solid" bordercolor="White">
<selecteditemstyle horizontalalign="Center" forecolor="Indigo" verticalalign="Middle" backcolor="#D8D8E6">
<edititemstyle horizontalalign="Center" forecolor="Indigo" verticalalign="Middle" backcolor="#D8D8E6">
<alternatingitemstyle horizontalalign="Center" forecolor="Indigo" verticalalign="Middle" backcolor="#D8D8E6">
<itemstyle horizontalalign="Center" forecolor="Indigo" verticalalign="Middle" backcolor="#D8D8E6">
<headerstyle horizontalalign="Center" forecolor="White" verticalalign="Middle" backcolor="DarkSlateBlue">
<columns>
<asp:templatecolumn sortexpression="siLineNumber" headertext="Delete">
<headerstyle horizontalalign="Center" forecolor="White" verticalalign="Middle" backcolor="DarkSlateBlue">
<itemstyle horizontalalign="Center" verticalalign="Middle" backcolor="#D8D8E6">
<itemtemplate>
<asp:checkbox id="CheckBox1" runat="server">
<asp:boundcolumn datafield="iQuoteId" sortexpression="iQuoteId" headertext="iQuoteId">
<headerstyle horizontalalign="Center" verticalalign="Middle">
<itemstyle horizontalalign="Center" verticalalign="Middle">
<asp:boundcolumn datafield="siLineNumber" sortexpression="siLineNumber" headertext="siLineNumber">
<headerstyle horizontalalign="Center" verticalalign="Middle">
<itemstyle horizontalalign="Center" verticalalign="Middle">
<asp:boundcolumn datafield="chSegmentDesc" sortexpression="chSegmentDesc" headertext="chSegmentDesc">
<headerstyle horizontalalign="Center" verticalalign="Middle">
<itemstyle horizontalalign="Center" verticalalign="Middle">
<asp:boundcolumn datafield="iMergeSegmentQty" sortexpression="iMergeSegmentQty" headertext="iMergeSegmentQty">
<headerstyle horizontalalign="Center" verticalalign="Middle">
<itemstyle horizontalalign="Center" verticalalign="Middle">
<asp:button id="Delete" style="Z-INDEX: 102; LEFT: 48px; POSITION: absolute; TOP: 32px" runat="server"
="" text="Delete"><asp:hyperlink id="HyperLink1" style="Z-INDEX: 103; LEFT: 832px; POSITION: absolute; TOP: 40px"
="" runat="server" navigateurl="ViewMergeSegments.asp">return
|
|
|
|
|
Hmm... well you're definately not getting the correct value of checked because it has to post back to the server in order for your code to see the right value. I'm not sure how to get it to post back in this instance, anybody else have any suggestions?
|
|
|
|
|
I am very carefull about declaring variables. But in a project i get out of memory exception, generally after close a form i use GC.Collect.
In this project , I connect a Sql Server with a sqlConnection declared as public in a module. Because in every task, i use this connection object. Before task i open that, when i achive the task, i close the connection. can This be cause?
|
|
|
|
|