How to click on a row in a datagrid, and popup a window, with the id of tat row being passed..?

How to click on a row in a datagrid, and popup a form, with the id of tat row being passed to the new form?

5 Replies

CB Clay Burch Syncfusion Team August 7, 2002 08:58 AM UTC

You can can do this in a mousedown event handler for your datagrid using a HitTest to get the row. You can also just use the CurrentRowIndex as weel since there will be a new currentrow at this point.
private void dataGrid1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
	Point pt = new Point(e.X, e.Y);
	MessageBox.Show(this.dataGrid1.HitTest(pt).Row.ToString());
}


CH cheryl August 7, 2002 11:20 PM UTC

> You can can do this in a mousedown event handler for your datagrid using a HitTest to get the row. You can also just use the CurrentRowIndex as weel since there will be a new currentrow at this point. > >
private void dataGrid1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
> {
> 	Point pt = new Point(e.X, e.Y);
> 	MessageBox.Show(this.dataGrid1.HitTest(pt).Row.ToString());
> }
wats HitTest? can pls explain to me? sorry i'm a newbie to VB.NET, but need this urgently for my work.


CH cheryl August 7, 2002 11:23 PM UTC

> > You can can do this in a mousedown event handler for your datagrid using a HitTest to get the row. You can also just use the CurrentRowIndex as weel since there will be a new currentrow at this point. > > > >
private void dataGrid1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
> > {
> > 	Point pt = new Point(e.X, e.Y);
> > 	MessageBox.Show(this.dataGrid1.HitTest(pt).Row.ToString());
> > }
> > wats HitTest? can pls explain to me? sorry i'm a newbie to VB.NET, but need this urgently for my work. And I'm using VB.NET not C leh.. is there any difference?


CB Clay Burch Syncfusion Team August 8, 2002 07:36 AM UTC

Take a look in your help index for HitTest method and then select the DataGrid.HitTest Method. The help there shows VB code for using this method. Here is the link. ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfSystemWindowsFormsDataGridClassHitTestTopic.htm


CB Clay Burch Syncfusion Team August 8, 2002 07:38 AM UTC

Another comment is that you don't really need the HitTest as if you click on a row, it normally becomes the currentrow. In that case, the member Me.DataGrid1.CurrentRowIndex will have the row number.

Loader.
Up arrow icon