Home Forums WinForms controls Xceed Grid for WinForms Right Click to select Row Reply To: Right Click to select Row

User (Old forums)
Post count: 23064

I don’t know why it takes so long, could be adding all those handlers. A better implementation might be:

Don’t do anything in the form load and add a mouse down event handler to the whole grid
Private Sub GridControl5_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If e.Button = MouseButtons.Right Then
Dim clickedCell As Xceed.Grid.Cell = DirectCast(GridControl5.GetVisualGridElementAtPoint(e.Location), Xceed.Grid.DataCell)
If Not (clickedCell Is Nothing) Then
Dim clickedRow = clickedCell.ParentRow
If Not (clickedRow Is Nothing) And clickedRow.CanBeCurrent Then
GridControl5.CurrentRow = clickedRow
GridControl5.CurrentRow.IsSelected = True
End If ‘Assing grid.ContextMenu based on CurrentRow (other code)
End If
End If
End Sub

I think that’s right, my Vb.NET code maybe a little sloppy but you get the idea.

Imported from legacy forums. Posted by Chris (had 3436 views)