DataGrid Double Click issue

Posted by: abellisomi on 27 October 2020, 4:11 am EST

  • Posted 27 October 2020, 4:11 am EST

    This issue is related to
    https://www.grapecity.com/forums/wpf-edition/datagrid-double-click-scro
    It happens when I double click on the Filter row.


    However that solution does not seem to work for us. I am using the `OriginalSource` to check if the parent is a DataGrid element, however sometimes it is, other times (when I click on empty text in a cell) the Parent is just a regular Windows Grid.
    This is the code I am using:

            private static bool IsDataGridRowEvent(object originalSource)
    {
    var element = originalSource as FrameworkElement;
    while (element != null)
    {
    if (element.Parent is DataGridCellPresenter)
    return true;

    element = element.Parent as FrameworkElement;
    }

    return false;
    }


    Any tip on how make this work? Thank you.

  • Replied 27 October 2020, 5:49 pm EST

    Hi,

    As I understand you want to capture mouse double click for a filter row, right? If so, did you try to use the LoadedRowPresenter event? Please check the following code once:
    Code:
    private void Grid_LoadedRowPresenter(object sender, C1.WPF.DataGrid.DataGridRowEventArgs e)
    {
    e.Row.Presenter.MouseDoubleClick += Presenter_MouseDoubleClick;
    }
    private void Presenter_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
    if (e.Source.GetType() == typeof(DataGridRowPresenter))
    //perform your task
    }
  • Replied 27 October 2020, 10:16 pm EST

    > As I understand you want to capture mouse double click for a filter row, right

    I want the double click to be fired ONLY for the data rows so not for
    - Filter rows
    - Scrollbars
    - Group rows
  • Marked as Answer

    Replied 29 October 2020, 3:40 am EST

    Hi,

    Yes, the above should work for this requirement.
    Just in case, the MouseDoubleClick event fires multiple times for each double click, after clicking the scrollbar etc, you may tweak the above code as follows:
    private void Grid_LoadedRowPresenter(object sender, C1.WPF.DataGrid.DataGridRowEventArgs e)
    {
    if (e.Row.Index > 0 && e.Row.Presenter.Tag == null)
    {
    e.Row.Presenter.MouseDoubleClick += Presenter_MouseDoubleClick;
    e.Row.Presenter.Tag = "Done";
    }
    }


    Regards,
  • Replied 10 November 2020, 6:20 am EST

    Works perfectly thank you!
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels