i need can select with a right click mouse in a ultragrid.
please help me.
Hello Alexander,
One possible solution is to handle the MouseUp event. In this event you can check the UIElement where the mouse was when click was performed. Check if this UIElement is RowUIElement or if any of its ancestors is such element. If so get the Row of the RowUIElement and activate it. Here is how you can achieve this:
private void UltraGrid1_MouseUp(object sender, MouseEventArgs e){ var grid = sender as UltraGrid; if(grid == null) return; // If this is not Right mouse button return if(e.Button != MouseButtons.Right) return; // Get the element under the mouse location var element = grid.DisplayLayout.UIElement.ElementFromPoint((e.Location)); // Check if the element is RowUIElement or if some of its ancestors // is RowUIElement RowUIElement rowElement = null; if(element is RowUIElement) rowElement = element as RowUIElement; else rowElement = element.GetAncestor(typeof(RowUIElement)) as RowUIElement; // If we have found a RowUIelement get its Row and activate it if(rowElement != null) rowElement.Row.Activate();}
// If this is not Right mouse button return if(e.Button != MouseButtons.Right) return;
// Get the element under the mouse location var element = grid.DisplayLayout.UIElement.ElementFromPoint((e.Location));
// Check if the element is RowUIElement or if some of its ancestors // is RowUIElement RowUIElement rowElement = null; if(element is RowUIElement) rowElement = element as RowUIElement; else rowElement = element.GetAncestor(typeof(RowUIElement)) as RowUIElement;
// If we have found a RowUIelement get its Row and activate it if(rowElement != null) rowElement.Row.Activate();}
Please let me know if you have any additional questions.
you can Give me the same code in Vb.net?
Here is the same code in VB:
Private Sub UltraGrid1_MouseUp(sender As Object, e As MouseEventArgs) Dim grid = TryCast(sender, UltraGrid) If grid Is Nothing Then Return End If ' If this is not Right mouse button return If e.Button <> MouseButtons.Right Then Return End If ' Get the element under the mouse location Dim element = grid.DisplayLayout.UIElement.ElementFromPoint((e.Location)) ' Check if the element is RowUIElement or if some of its ancestors ' is RowUIElement Dim rowElement As RowUIElement = Nothing If TypeOf element Is RowUIElement Then rowElement = TryCast(element, RowUIElement) Else rowElement = TryCast(element.GetAncestor(GetType(RowUIElement)), RowUIElement) End If ' If we have found a RowUIelement get its Row and activate it If rowElement IsNot Nothing Then rowElement.Row.Activate() End IfEnd Sub
' If this is not Right mouse button return If e.Button <> MouseButtons.Right Then Return End If
' Get the element under the mouse location Dim element = grid.DisplayLayout.UIElement.ElementFromPoint((e.Location))
' Check if the element is RowUIElement or if some of its ancestors ' is RowUIElement Dim rowElement As RowUIElement = Nothing If TypeOf element Is RowUIElement Then rowElement = TryCast(element, RowUIElement) Else rowElement = TryCast(element.GetAncestor(GetType(RowUIElement)), RowUIElement) End If
' If we have found a RowUIelement get its Row and activate it If rowElement IsNot Nothing Then rowElement.Row.Activate() End IfEnd Sub
Please let me know if any additional questions arise.