Datagrid select row
-
Hi there can someone please help me? I want to select a row from form1 and then open another form (form2) which shows the same row but with some more fields... so.. form 1. datagrid about 4 collums from the database table. then dubbel click on it form 2. a couple of textfields.. (about 10) which shows all the records in the row. i use C# winforms. i've tried a lot of thinks but it just won't work....
-
Hi there can someone please help me? I want to select a row from form1 and then open another form (form2) which shows the same row but with some more fields... so.. form 1. datagrid about 4 collums from the database table. then dubbel click on it form 2. a couple of textfields.. (about 10) which shows all the records in the row. i use C# winforms. i've tried a lot of thinks but it just won't work....
Moddify the constructor of form2 so that it takes the ID of the row and then display the information you need. On form1 make a event hanlder that will respond to the doubleclick on the datagrid and then make a new form in that event handler that will pass the id of the row to the form2. Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!
-
Moddify the constructor of form2 so that it takes the ID of the row and then display the information you need. On form1 make a event hanlder that will respond to the doubleclick on the datagrid and then make a new form in that event handler that will pass the id of the row to the form2. Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!
but how? i actualy got al the coding.. but it just don't work.. and i really dont know why.
public void dataGrid_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { int rowIndex = dataGrid1.CurrentRowIndex; if (CustomRow != null) { CustomRow(this, new CustomRowEventArgs(barry11,dataGrid1,rowIndex)); } }
public class CustomRowEventArgs : EventArgs { public Barry1 DaSet; DataGrid grid; int row; public CustomRowEventArgs(Barry1 DSet,DataGrid Grid,int Row) { DaSet = DSet; grid = Grid; row = Row; } public Barry1 DSet { get { return DaSet; } } public DataGrid Grid { get { return grid; } } public int Row { get { return row; } }
that DaSet.. should be barry11 (my dataset) DaSet was kinne like a test or something.. or what variable or class or something should i put there..public virtual void customHandler_CustomRow(object sender, CustomRowEventArgs e) { Barry1 DaSet = e.DaSet; DataGrid dataGrid1 = e.Grid; int row = e.Row; textBox.Text = dataGrid1[e.Row,0].ToString();
this textbox stands on the same form so i could test it and see it quick if it works or not.. but it doesn't... -
Moddify the constructor of form2 so that it takes the ID of the row and then display the information you need. On form1 make a event hanlder that will respond to the doubleclick on the datagrid and then make a new form in that event handler that will pass the id of the row to the form2. Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!
Quick'n dirty... In the main form, when a row in the datagrid is double clicked:
private void dgInfo_DoubleClick(object sender, System.EventArgs e) { Form2 frm=new Form2(ds, dgInfo.CurrentRowIndex); frm.ShowDialog(); }
In the constructor of Form2:public Form2(DataSet ds, int index):this() { textBox1.Text=ds.Tables[0].Rows[index][0].ToString(); textBox2.Text=ds.Tables[0].Rows[index][1].ToString(); textBox3.Text=ds.Tables[0].Rows[index][2].ToString(); }
Helpful perhaps...