How can I make right clicking activate a row?
This code is lifted directly out of one of our projects so some parts will not be relevant but it should point you in the right direction.
' When the right mouse button has been clicked, select the row if it is not already selected
If (e.Button = System.Windows.Forms.MouseButtons.Right) Then
If (cell IsNot Nothing AndAlso cell.IsDataCell AndAlso Not cell.Row.Selected) Then
listGrid.Selected.Rows.Clear()
cell.Row.Activate()
cell.Row.Selected = True
End If
End Sub
Andy Jones said: This code is lifted directly out of one of our projects so some parts will not be relevant but it should point you in the right direction.Private Sub listGrid_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles listGrid.MouseDown ' When the right mouse button has been clicked, select the row if it is not already selected If (e.Button = System.Windows.Forms.MouseButtons.Right) ThenDim cell As UltraGridCell = GetCellAtPoint(New Point(e.X, e.Y)) If (cell IsNot Nothing AndAlso cell.IsDataCell AndAlso Not cell.Row.Selected) Then listGrid.Selected.Rows.Clear() cell.Row.Activate() cell.Row.Selected = True End If End IfEnd Sub
cell.Row.Selected =
This looks like it might work, but where is the GetCellAtPoint() method? What object does that belong to?
0to600 said: This looks like it might work, but where is the GetCellAtPoint() method? What object does that belong to?
Sorry, it was lifted a little too quickly!
Here's the method, it's one of ours but from then on in it's Infragistics.
''' <summary>
''' Gets the cell in the grid at a particular point (if any).
''' </summary>
''' <param name="point">Point at which to check grid.</param>
''' <returns>Returns the cell found at the specified point, or nothing if not a cell.</returns>
Dim element As UIElement = listGrid.DisplayLayout.UIElement.ElementFromPoint(point)
Return cell
listGrid is the UltraGrid in question.