Column Name by clicking?

bonedoc

Well-known member
Joined
May 4, 2006
Messages
112
Programming Experience
Beginner
I have a datagrid, and I need to get the name of it by a click event (of the headers). I have been playing around with this, but no luck. I get a null ref:

VB.NET:
Private Sub dataGrid_MouseUp(ByVal o As Object, ByVal mea As MouseEventArgs) Handles dataGrid.mousedoubleclick
 
Dim hitTest As DataGrid.HitTestInfo
 
' Get the name of the column that was clicked.
 
messagebox.show(dataTable.Columns(hitTest.Column).ColumnName)
 
End Sub
 
Last edited by a moderator:
You also have to perform the hittest to get some value into that empty variable (hitTest). Do this and it will work if your dataTable is an actual instance of a DataTable. You should name your variables and objects to avoid such confusion!
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] hitTest [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataGrid.HitTestInfo = dataGrid.HitTest(e.X, e.Y)
[/SIZE]

 
Back
Top