Home Forums WinForms controls Xceed Grid for WinForms Selecting row with right-click of mouse

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

    Currently, if I right click on an unselected row, it brings up the context menu of the previously selected row.  This is because it is not selecting the row where the cursor is clicked, but rather just referencing the currently clicked row.  The result is that you have to left-click the row and then right-click it to bring up the context menu.

    Is there a way to get it to select the row that you right-click on so that it takes only one click to bring up the context menu on a desired row?

    Imported from legacy forums. Posted by Daniel (had 2282 views)

    User (Old forums)
    Member
    Post count: 23064

    With the kind assistance of Xceed tech support, I was able to craft the following solution.  The “AddMouseEvents” procedure is called right after databinding.

    Private Sub AddMouseEvents(ByVal sender As Object, ByVal e As EventArgs)

    Dim c As Xceed.Grid.DataCell

    Dim r As Xceed.Grid.DataRow

    For Each r In mygrid.DataRows

    For Each c In r.Cells

    AddHandler c.MouseDown, AddressOf Cell_MouseDown

    Next

    Next

    End Sub

    Private Sub Cell_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)

    Dim c As Xceed.Grid.Cell = (CType(sender, Xceed.Grid.Cell))

    Dim p As System.Drawing.Point = c.ClientPointToGrid(New System.Drawing.Point(e.X, e.Y))

     

    If e.Button = System.Windows.Forms.MouseButtons.Right Then

    Dim alreadyselected As Boolean = False

    Dim r As Xceed.Grid.DataRow

    For Each r In mygrid.SelectedRows

    If r Is c.ParentRow Then

    alreadyselected =

    True

    Exit For

    End If

    Next

    If Not alreadyselected Then

    mygrid.SelectedRows.Clear()

    mygrid.SelectedRows.Add(c.ParentRow)

    CType(c.ParentRow, Xceed.Grid.DataRow).Invalidate()

    End If

    mygrid.ContextMenuStrip.Show(mygrid, p)

    End If

    End Sub

    Imported from legacy forums. Posted by Daniel (had 1106 views)

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