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

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)