Search Amazon:

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())  	
    Else  	
        If hti.Type = DataGrid.HitTestType.ColumnHeader Then 
          '
          ' Assumes the DataSource is a DataView.  	
          '
          MessageBox.Show(CType(Me.DataGrid.DataSource,  _
              DataView).Table.Columns(hti.Column).ToString())  	
        End If  	
    End If 	
Sign In
  User Id 
  Password 


Submit Your Own Code and Articles




About TheScarms
About TheScarms

Ask me your programming questions

I read every email and answer all I can.

User Feedback: Be the first to add a comment! Items to Show:     

     
You must log in to post feedback.
Comment:    
 

If you use this code, please mention "www.TheScarms.com"

Email this page


TheScarms AppSentinel lets you securely copy protect and create evaluation versions of your software

TheScarms(tm) AppSentinel lets you quickly and easily create evaluation versions of your software and stop unauthorized copying and unregistered use of your programs!

Get your free
trial copy today!


      The World's Number 1 Web Host

© Copyright 2008 TheScarms