RadGridView Row double click event handling (Exclude double click on header and row details)

1 Answer 1109 Views
GridView
Kamran
Top achievements
Rank 3
Iron
Iron
Veteran
Kamran asked on 23 Aug 2021, 03:00 PM

Hi,

This is bit outdated question, but I want to handle GridviewRow double click event more efficiently.

My grid view contains RowDetails template (Tab control). Row details contains summary and attachment tab. While attachment tab displays attachments in girdview control.

I had registered GridviewRow double click event in parent GridView as


private void GridView_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
        {
            if (e.Row is GridViewRow)
            {
                e.Row.AddHandler(GridViewRow.MouseDoubleClickEvent, new MouseButtonEventHandler(OnRowMouseDoubleClick), false);
            }
        }

Double click event is fired as expected but with following exception (which is not required), but as per behavior its valid.

  • Double click event triggered by double click on parent gridview header
  • Double click event triggered by double click on GridviewRow details (even scroll bar in attachment gridview)

To overcome these I added following checks


private async void OnRowMouseDoubleClick(object sender, MouseButtonEventArgs args) { FrameworkElement originalSender = args.OriginalSource as FrameworkElement; var cell = originalSender.ParentOfType<GridViewCell>(); if (cell == null) { return; } var selectedRowContext = ((System.Windows.FrameworkElement)sender).DataContext as MyDataContext; if (selectedRowContext == null) return;

}

Basically I am validating Gridview Header and RowDetails gridview scrollbar by "cell" in above example.

While I validate Row details double click by selectedRowContext as there datacontext is different from MyDataContext.

I feel that this is temporary solution. I want to fix it, i.e. double click only happens on DataRow or Data cell. All other controls in Gridview should be excluded.

 

 

 

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 25 Aug 2021, 11:10 AM

Hi Kamran,

Thank you for the provided code snippets.

I want to start by clarifying that the OnRowMouseDoubleClick handler is not fired when double-clicking on the parent header rows at my end. I've prepared a small sample project to demonstrate this.

As for the click in the row details, you can add the following logic to check whether the details element is clicked:

        private void OnRowMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            FrameworkElement originalSender = e.OriginalSource as FrameworkElement;
            var detailsPresenter = originalSender.ParentOfType<DetailsPresenter>();

            if (detailsPresenter != null)
            {
                return;
            }
        }

This seems to provide the expected behavior at my end. Please, however, have a look at the attached project and let me know if I'm missing something of importance.

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
GridView
Asked by
Kamran
Top achievements
Rank 3
Iron
Iron
Veteran
Answers by
Dilyan Traykov
Telerik team
Share this question
or