Select Row
-
I have a problem using a datagrid. I have 2 forms. 1 with a data grid and one textbox (for test use) and the second form has a couple of textboxes. now i use a CustomRowEventArgs to select the row. In form 1 this works.. I can even read The first collumn in the Textbox (for test use) I also let him open the second form. but there it does nothing. If needed I can past the code or pieces of the code here. I really need some help..
-
I have a problem using a datagrid. I have 2 forms. 1 with a data grid and one textbox (for test use) and the second form has a couple of textboxes. now i use a CustomRowEventArgs to select the row. In form 1 this works.. I can even read The first collumn in the Textbox (for test use) I also let him open the second form. but there it does nothing. If needed I can past the code or pieces of the code here. I really need some help..
-
Sorry, but i didn't get what are u trying to do? can u explain in detail and paste some code Regards, Pramod
The second form should be showing all the info that's clicked on the row of the datagrid on the first form . but in checkboxes. my code: it's looks kinna messy but i only post the important pieces here. Form 1
public delegate void CustomRowHandler(object sender, CustomRowEventArgs e); public static event CustomRowHandler CustomRow; InitializeComponent(); barryOracleDataAdapter1.Fill(barry11.Barry); CustomRow += new CustomRowHandler(customHandler_CustomRow); private void customHandler_CustomRow(object sender, WindowsApplication30.CustomRowEventArgs e) { Barry1 DSet = e.DSet; DataGrid grid = e.Grid; int row = e.Row; textBox2.Text = e.DSet.Tables[0].Rows[e.Row]["lastname"].ToString(); public void dataGrid_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { int rowIndex = dataGrid.CurrentRowIndex; if (CustomRow != null) { CustomRow(this, new CustomRowEventArgs(barry11,dataGrid, rowIndex)); DataForm1 frm = new DataForm1 (barry11,dataGrid, dataGrid.CurrentRowIndex); frm.Show(); } } public class CustomRowEventArgs : EventArgs { Barry1 barry11; DataGrid grid; int row; public CustomRowEventArgs(Barry1 DSet,DataGrid Grid,int Row) { barry11 = DSet; grid = Grid; row = Row; } public Barry1 DSet { get { return barry11; } } public DataGrid Grid { get { return grid; } } public int Row { get { return row; } } }
--------------------------------------------------------------------------- Form 2public DataForm1(Barry1 barry11, DataGrid dataGrid, int rowIndex) { // // Required for Windows Form Designer support // InitializeComponent(); Form1.CustomRow += new WindowsApplication30.CustomRowHandler(customHandler_CustomRow); private void customHandler_CustomRow(object sender, WindowsApplication30.CustomRowEventArgs e) { Barry1 DSet = e.DSet; DataGrid grid = e.Grid; int row = e.Row; editLASTNAME.Text = e.DSet.Tables[0].Rows[e.Row]["Firstname"].ToString(); }
-
The second form should be showing all the info that's clicked on the row of the datagrid on the first form . but in checkboxes. my code: it's looks kinna messy but i only post the important pieces here. Form 1
public delegate void CustomRowHandler(object sender, CustomRowEventArgs e); public static event CustomRowHandler CustomRow; InitializeComponent(); barryOracleDataAdapter1.Fill(barry11.Barry); CustomRow += new CustomRowHandler(customHandler_CustomRow); private void customHandler_CustomRow(object sender, WindowsApplication30.CustomRowEventArgs e) { Barry1 DSet = e.DSet; DataGrid grid = e.Grid; int row = e.Row; textBox2.Text = e.DSet.Tables[0].Rows[e.Row]["lastname"].ToString(); public void dataGrid_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { int rowIndex = dataGrid.CurrentRowIndex; if (CustomRow != null) { CustomRow(this, new CustomRowEventArgs(barry11,dataGrid, rowIndex)); DataForm1 frm = new DataForm1 (barry11,dataGrid, dataGrid.CurrentRowIndex); frm.Show(); } } public class CustomRowEventArgs : EventArgs { Barry1 barry11; DataGrid grid; int row; public CustomRowEventArgs(Barry1 DSet,DataGrid Grid,int Row) { barry11 = DSet; grid = Grid; row = Row; } public Barry1 DSet { get { return barry11; } } public DataGrid Grid { get { return grid; } } public int Row { get { return row; } } }
--------------------------------------------------------------------------- Form 2public DataForm1(Barry1 barry11, DataGrid dataGrid, int rowIndex) { // // Required for Windows Form Designer support // InitializeComponent(); Form1.CustomRow += new WindowsApplication30.CustomRowHandler(customHandler_CustomRow); private void customHandler_CustomRow(object sender, WindowsApplication30.CustomRowEventArgs e) { Barry1 DSet = e.DSet; DataGrid grid = e.Grid; int row = e.Row; editLASTNAME.Text = e.DSet.Tables[0].Rows[e.Row]["Firstname"].ToString(); }
-
just change the following statement DataForm1 frm = new DataForm1 (barry11,dataGrid, dataGrid.CurrentRowIndex); with DataForm1 frm = new DataForm1 (barry11,dataGrid, rowIndex); Hope that solves ur problem Regards, Pramod
Too bad.. I've tried that but the problem remains.
-
Too bad.. I've tried that but the problem remains.
does anyone else have some solution or information?
-
does anyone else have some solution or information?
I suggest you skip the event handling i the second form. I really can't see the purpose of it. But, perhaps I get it wrong. Just assign the values to the textbox in the second form. You've got all the information you need through the constructor. Like this:
public DataForm1(Barry1 barry11, DataGrid dataGrid, int rowIndex) { // // Required for Windows Form Designer support // InitializeComponent(); PopulateTextBoxes(barry11, dataGrid, rowIndex); private void PopulateTextBoxes(Barry1 barry11, DataGrid dataGrid, int rowIndex) { editLASTNAME.Text = barry11.Tables[0].Rows[rowIndex]["Firstname"].ToString(); }
-
I suggest you skip the event handling i the second form. I really can't see the purpose of it. But, perhaps I get it wrong. Just assign the values to the textbox in the second form. You've got all the information you need through the constructor. Like this:
public DataForm1(Barry1 barry11, DataGrid dataGrid, int rowIndex) { // // Required for Windows Form Designer support // InitializeComponent(); PopulateTextBoxes(barry11, dataGrid, rowIndex); private void PopulateTextBoxes(Barry1 barry11, DataGrid dataGrid, int rowIndex) { editLASTNAME.Text = barry11.Tables[0].Rows[rowIndex]["Firstname"].ToString(); }
Dude you really are great It works at once. I would like to thank you 1000 time but hope you agree with one big Thanks. Thank you so verry much you really are awesome.
-
Dude you really are great It works at once. I would like to thank you 1000 time but hope you agree with one big Thanks. Thank you so verry much you really are awesome.
-
Oh just one thing:P now I have this datagrid and a detail form. now i adjust my button. i want a previos button on my second form.. code on form1: this is on my mouse up event of my datagrid -------------------------------------
DataForm1 tmpForm = new DataForm1 (barry11,dataGrid, rowIndex); tmpForm.Location = this.Location; tmpForm.Show(); this.Hide();
--------------------------------------------- DataForm1:private System.Windows.Forms.Form _previousForm;
and then comes this.. thinks this is a really bad way to do it:Ppublic DataForm1(Barry1 barry11, DataGrid dataGrid, int rowIndex) { InitializeComponent(); PopulateTextBoxes(barry11, dataGrid, rowIndex); } public DataForm1(System.Windows.Forms.Form tmpForm) { InitializeComponent(); _previousForm = tmpForm; }
think this should be done other than this.. but i don't know how:( last peace of codeprivate void btnbutton1_Click(object sender, System.EventArgs e) { // show previous _previousForm.Location = this.Location; _previousForm.Show(); // close this form this.Close(); }
-
Oh just one thing:P now I have this datagrid and a detail form. now i adjust my button. i want a previos button on my second form.. code on form1: this is on my mouse up event of my datagrid -------------------------------------
DataForm1 tmpForm = new DataForm1 (barry11,dataGrid, rowIndex); tmpForm.Location = this.Location; tmpForm.Show(); this.Hide();
--------------------------------------------- DataForm1:private System.Windows.Forms.Form _previousForm;
and then comes this.. thinks this is a really bad way to do it:Ppublic DataForm1(Barry1 barry11, DataGrid dataGrid, int rowIndex) { InitializeComponent(); PopulateTextBoxes(barry11, dataGrid, rowIndex); } public DataForm1(System.Windows.Forms.Form tmpForm) { InitializeComponent(); _previousForm = tmpForm; }
think this should be done other than this.. but i don't know how:( last peace of codeprivate void btnbutton1_Click(object sender, System.EventArgs e) { // show previous _previousForm.Location = this.Location; _previousForm.Show(); // close this form this.Close(); }
I really see no need to hide the first form. I would do like this instead...
DataForm1 tmpForm = new DataForm1 (barry11,dataGrid, rowIndex); //tmpForm.Location = this.Location; tmpForm.ShowDialog(); //this.Hide();
...and skip all the code to restore the first form in DataForm1. -
I really see no need to hide the first form. I would do like this instead...
DataForm1 tmpForm = new DataForm1 (barry11,dataGrid, rowIndex); //tmpForm.Location = this.Location; tmpForm.ShowDialog(); //this.Hide();
...and skip all the code to restore the first form in DataForm1.but i really want to hide the first form:P