Hi!
I'm using the xamDatagrid and have a handler implemented for the MouseDoubleClick event to perform an action when a row is double clicked. However if the user is quickly clicking the vertical scroll bar to quickly scroll through the list the MouseDoubleClick event also fires (which is reasonable since the MouseDoubleClick event is on the grid itself). I can easily test in the code if there are any items selected to handle the case where no item is previously selected but when a row has already been selected I need to differentiate between the double click on a row and double (or multiple) clicks on the scroll bar. Is there any way to differentiate between these events???
Thanks!
GlennL
is it possible to see this code in VB
Hey Andrew,
Thanks, the solution you provided seems to work perfectly! So far in my experience it only resolves to true if the user clicks on a data row, and I have Images, TextBlocks, and XamTextEditors in my rows. It also doesn't resolve to true if the scroll bar is clicked or if a column header is clicked. This is exactly what we want.
Thanks again!
Mel
TextBlocks can exist within other elements besides cells (labels, groupby area prompts, etc.). We have some utility methods in our Windows assembly which may help. e.g.
if (null != Utilities.GetAncestorFromType(e.OriginalSource as DependencyObject, typeof(DataRecordCellArea), true)) { ... }
Here's a solution which worked for me and is a little shorter - my cells only have TextBlocks or XamTextEditors.
private void xamDataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e){ // Check that a row is clicked on // Ignore double clicks on the scroll bar or in the empty space outside the rows if ((e != null) && (e.MouseDevice != null)) { IInputElement over = e.MouseDevice.DirectlyOver; if ((over is TextBlock) || (over is Infragistics.Windows.Editors.XamTextEditor)) ViewDetails_Executed(sender, null); else Debug.WriteLine("Grid double-click ignored: over " + over); } } // xamDataGrid_MouseDoubleClick()
I ran into the same issue, here's my solution:
private void xamGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (IsXamGridItem(e.OriginalSource as DependencyObject))
// Do Stuff
}
public static bool IsXamGridItem(DependencyObject source)
if (source == null)
return false;
if (IsVisualParentOfType<DataRecordCellArea, XamDataGrid>(source as UIElement))
return true;
public static bool IsVisualParentOfType<visualType, rootType>(UIElement visual)
if (visual == null)
var element = VisualTreeHelper.GetParent(visual) as UIElement;
while (element != null)
if (element is visualType)
if (element is rootType)
element = VisualTreeHelper.GetParent(element) as UIElement;