Get the DataGrid row or column that was clicked

You can use the DataGrid's HitTest method, passing it a point in the grid's client coordinate system, and returning a HitTestInfo object that holds all the row and column information.

    ' X and Y are in the grid's coordinates. If they are in
    ' screen coordinates, call DataGrid.PointToClient method.  	
    Dim pt = New Point(X, Y)  	
    Dim hti As DataGrid.HitTestInfo = Me.DataGrid.HitTest(pt)  	

    If hti.Type = DataGrid.HitTestType.Cell Then  	
        MessageBox.Show(DataGrid(hti.Row, hti.Column).ToString())  	
        If hti.Type = DataGrid.HitTestType.ColumnHeader Then 
          ' Assumes the DataSource is a DataView.  	
          MessageBox.Show(CType(Me.DataGrid.DataSource,  _
        End If  	
    End If 	

About TheScarms
About TheScarms

Sample code
version info

If you use this code, please mention ""

Email this page

© Copyright 2016 TheScarms
Goto top of page