Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to highlight Row In Windows Forms DataGrid control?

How-to

How to highlight Row In Windows Forms DataGrid control?

by  PankajBanga  Posted    (Edited  )

In VS.NET, the DataGrid default selection property differs from the MS Flexigrid in VB 6. When a user clicks on a populated DataGrid in .NET, the cursor is placed inside the cell for editing. The following sample illustrates how to highlight the entire row when a user clicks on a cell. It calls the HitTest method on MouseUp event handler, which returns a DataGrid.HitTestInfo object that contains information about a part of the DataGrid clicked.

Private Sub onDataGridMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp
Dim pt = New Point(e.X, e.Y)
Dim hit As DataGrid.HitTestInfo = DataGrid1.HitTest(pt)

If hit.Type = Windows.Forms.DataGrid.HitTestType.Cell Then
DataGrid1.CurrentCell = New DataGridCell(hit.Row, hit.Column)
DataGrid1.Select(hit.Row)
End If
End Sub

If you find the sample useful, please don't forget to Rate this and other samples. Your feedback will be much appreciated and valued and will keep me triggering. GOOD LUCK!!!
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top