Hi
I have a UltraWinGrid with many rows, When user double clicks on a row, Application leads to details of that row.
I use Grid_DoubleClick event for this.
But even when user clicks twice on scroll bar, this event is fired and detail screen pops up.
How could I catch double click only on data row?
Thanks
Shivangi
You should use MouseDoubleClick instead (better because it gives you the point that was clicked, and it is expressed in client coordinates). In the event handler, you could cast the sender to an UltraGrid, get the UltraGrid.DisplayLayout.UIElement, and use ElementFromPoint to find the RowUIElement that was double-clicked (if any).
Example:void ultraGrid_MouseDoubleClick(object sender, MouseEventArgs e){ UltraGrid control = sender as UltraGrid; UIElement controlElement = control != null ? control.DisplayLayout.UIElement : null; UIElement elementAtPoint = controlElement != null ? controlElement.ElementFromPoint(e.Location) : null;
UltraGridRow row = null; while ( elementAtPoint != null ) { RowUIElement rowElement = elementAtPoint as RowUIElement; if ( rowElement != null ) { row = rowElement.Row; break; }
elementAtPoint = elementAtPoint.Parent; }
if ( row != null ) { // If you get in here a row was double-clicked. }}
Hi Brian,
I understand your point but I need to develope this application in Visual studio 2002 and it does not include MouseDoubleClick event, thus I am using this work around.
Thank you for the response Brain,
But I could not find MouseDoubleClick event, may be I am using older version.
I tried following code and it worked fine
Private Sub UltraGrid1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles UltraGrid1.DoubleClick 'Cast the sender into an UltraGrid Dim grid As UltraGrid = DirectCast(sender, UltraGrid) 'Get the last element that the mouse entered Dim lastElementEntered As UIElement = grid.DisplayLayout.UIElement.LastElementEntered 'See if there's a RowUIElement in the chain. Dim rowElement as RowUIElement If TypeOf lastElementEntered is RowUIElement Then rowElement = DirectCast(lastElementEntered, RowUIElement) Else rowElement = DirectCast(lastElementEntered.GetAncestor(GetType(RowUIElement)), RowUIElement) End If If rowElement is Nothing Then Return 'Try to get a row from the element Dim row As UltraGridRow = DirectCast(rowElement.GetContext(GetType(UltraGridRow)), UltraGridRow) 'If no row was returned, then the mouse is not over a row. If (row Is Nothing) Then Return 'The mouse is over a row. 'This part is optional, but if the user double-clicks the line 'between Row selectors, the row is AutoSized by 'default. In that case, we probably don't want to do 'the double-click code. 'Get the current mouse pointer location and convert it 'to grid coords. Dim MousePosition As Point = grid.PointToClient(Control.MousePosition) 'See if the Point is on an AdjustableElement - meaning that 'the user is clicking the line on the row selector If Not lastElementEntered.AdjustableElementFromPoint(MousePosition) Is Nothing Then Return 'Everthing looks go, so display a message based on the row. MessageBox.Show(Me, "The key of the row is:" + row.Cells(0).Value.ToString())End Sub