posted on Monday, February 16, 2004 10:52 PM
by
demiliani
Catching a doubleclick on a Datagrid...
Yes, this is my problem of the day...
For an application that we're developing at work, I need to catch a doubleclick on a datagrid row and, after that, displaying details about the selected row. I've just discovered that catching a doubleclick on a datagrid row is not so simple...
On Syncfusion I've found a little explanation for this problem:
The problem is that the first click of a double click may be caught by the datagrid (and used to activate the cell) while the second click goes to the TextBox for the columnstyle object. This means the TextBox thinks this is a singleclick, and does not fire its doubleclick event. One solution is to mark the time of the click caught by the datagrid. Then look at this time in the TextBox's mousedown handler to see if in fact the single click being looked at by the TextBox is part of a double click.
So, after that, I've tryed the solution described as follows:
During the Datagrid format, I've added this ColumnStyle (for each column):
Private
Sub AddCustomDataTableStyle()Dim ts1 As DataGridTableStyle
ts1 = New DataGridTableStyle()
ts1.MappingName = "Customers"
' Set other properties.
ts1.AlternatingBackColor = Color.LightGray
' Add textbox column style so we can catch textbox mouse clicks (this code for every column in the Datagrid)
Dim TextCol As DataGridTextBoxColumn
TextCol = New DataGridTextBoxColumn()
TextCol.MappingName = "custID"
TextCol.HeaderText = "CustomerID"
TextCol.Width = 100
'Add handler
AddHandler TextCol.TextBox.MouseDown, New MouseEventHandler(AddressOf TextBoxMouseDownHandler)
AddHandler TextCol.TextBox.DoubleClick, New EventHandler(AddressOf TextBoxDoubleClickHandler)
ts1.GridColumnStyles.Add(TextCol)
End Sub
The Events are declared as follow:
Private
Sub TextBoxDoubleClickHandler(ByVal sender As Object, ByVal e As EventArgs)MessageBox.Show("This is a True DoubleClick")
End Sub
Private Sub TextBoxMouseDownHandler(ByVal sender As Object, ByVal e As MouseEventArgs)
If (DateTime.Now < gridMouseDownTime.AddMilliseconds(SystemInformation.DoubleClickTime)) Then
MessageBox.Show("This is a Grid DoubleClick")
End If
End Sub
Is there an other possible solution to this problem? I don't like a lot the solution described above... How can I catch a Doubleclick? Is it possible that there's no property or events for doing that?