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

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #14294 |

    I have the following code for selecting a row by right clicking. The first time I right click on a row, it will take a few seconds before the row is selected. After that, right clicking on any row will select the row instantly. Any ideas why???

    In Form Load:
    GridControl5.BeginInit()
    Dim row4 As Xceed.Grid.DataRow
    For Each row4 In GridControl5.DataRows
    Dim cell As Cell
    For Each cell In row4.Cells
    AddHandler cell.MouseDown, AddressOf Data_MouseDown
    Next cell
    Next row4
    GridControl5.EndInit()

    Private Sub Data_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
    If e.Button = MouseButtons.Right Then
    Dim row As Xceed.Grid.Row = Nothing
    row = CType(sender, Xceed.Grid.DataCell).ParentRow
    If Not (row Is Nothing) Then
    If row.CanBeCurrent Then
    GridControl5.CurrentRow = row
    GridControl5.CurrentRow.BringIntoView()
    GridControl5.SelectedRows.Clear()
    GridControl5.CurrentRow.IsSelected = True
    End If ‘Assing grid.ContextMenu based on CurrentRow (other code)
    End If
    End If
    End Sub

    Thanks

    Imported from legacy forums. Posted by nova123 (had 2437 views)

    User (Old forums)
    Member
    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
    <PRE>
    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.BringIntoView()
    GridControl5.SelectedRows.Clear()
    GridControl5.CurrentRow.IsSelected = True
    End If ‘Assing grid.ContextMenu based on CurrentRow (other code)
    End If
    End If
    End Sub
    </PRE>

    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)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.