Identify what cell has been click

dawnKo

Member
Joined
Jul 10, 2006
Messages
11
Programming Experience
Beginner
Hi all,
I need help urgently.. I need a function that enable user to click on the cell of the datagrid and then there will be 3 combo boxes and a textbox that will display the details of the selected cell from the database. How can i know which cell is being click on so that i can retrieve the row of details?
 
This snippet may be of use to you. It uses the HitTestInfo class of the datagrid to determine where the mouse was clicked and then retrieves the row or columnheader that was clicked at displays it in a messagebox.

VB.NET:
Dim pt = New Point(X, Y)
Dim hti As DataGrid.HitTestInfo = dataGrid1.HitTest(pt)
If hti.Type = DataGrid.HitTestType.Cell Then  
MessageBox.Show(dataGrid1(hti.Row, hti.Column).ToString())
Else  
If hti.Type = DataGrid.HitTestType.ColumnHeader Then    'assumes datasource is a dataview    
MessageBox.Show(CType(DataGrid1.DataSource, DataView).Table.Columns(hti.Column).ToString())  
End If
End If
 
Hi vis781,
Thanks for the help. But the grid im using is datagridview which doesnt seem to have the HitTestInfo method.
 
dawnKo, you did ask about the DataGrid control, which is a very different control from the DataGridView, both valid of your .Net 2.0 platform, although DataGrid only remains for backward compability. So you must take care to be specific in your request to avoid such unnecessary confusion.

Dealing with the DataGridView is much easier, just check the CellClick event, the e parameter of event handler provides ColumnIndex and RowIndex.
 
HI all.... sorry about the confusion caused. The one i wanted is datagridview sorry if it had mislead u guys....
 
Back
Top