I need to be able to expand collapse rowdetails by clicking anywhere on the row and not just using the toggle button column. How do I achieve this?
Thanks.
Cheers!
Ganesh
12 Answers, 1 is accepted
if (!e.AddedItems.Any()) e.Handled = true; else { var gridView = (RadGridView) sender; var selectedRow = gridView.ItemContainerGenerator.ContainerFromItem(e.AddedItems[0]) as GridViewRow; if (selectedRow == null) return; selectedRow.DetailsVisibility = selectedRow.DetailsVisibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible; gridView.SelectedItem = null; }Hope this helps someone else!
Cheers!
Ganesh
Thank you for sharing your solution.
A better approach would be to subscribe for the MouseLeftButtonDown event and then execute your logic:
void MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e){ var row = (sender as TextBlock).ParentOfType<GridViewRow>(); row.DetailsVisibility = row.DetailsVisibility == System.Windows.Visibility.Visible ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible;}Greetings,
Didie
the Telerik team
Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.
Do you mean hook up to MouseLeftButtonDown on the GridView or on each column? I hooked up the GridView but it doesnt seem to be firing the event?
Regards,
Ganesh
For example, if the GridView is named 'clubsGrid', then the code to subscribe for the event
would be:
this.clubsGrid.AddHandler(FrameworkElement.MouseLeftButtonDownEvent, new System.Windows.Input.MouseButtonEventHandler(OnMouseDown), true);Didie
the Telerik team
Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.
Is this not same as doing?
clubGrid.MouseLeftButtonDown += OnMouseLeftButtonDown;With AddHandler approach you can handle even events marked as Handled (the third argument).
Regards,Vlad
the Telerik team
Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.
I tried your approach. But the sender in the MouseDownEvent is GridView and not a TextBlock. So doing a ParentOfType on GridView is not going to give the GridViewRow. How do we resolve this?
Ganesh
You are right. In that case the sender is the RadGridView. That is why you should use the e.OriginalSource instead:
void MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e){var s = e.OriginalSource as FrameworkElement;var row = s.ParentOfType<GridViewRow>();
if (row != null)
{ row.DetailsVisibility = row.DetailsVisibility == System.Windows.Visibility.Visible ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible;
} }Didie
the Telerik team
Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.
This works okay. But there's a bigger problem. Now when the row details is expanded and I click anything on the row details, it collapses the row details. In my case I have a tabcontrol in the rowdetails with some editable form. The moment I click on a button, for example, in it, it collapses the row details.
Looking at my scenario it doesnt seem possible to achieve the behavior i want?
Ganesh
You can two additional checks in case you have another GridView in RowDetails.
For example:
void MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { var s = e.OriginalSource as FrameworkElement; var cell = s.ParentOfType<GridViewCell>(); if (cell != null) { var row = cell.ParentOfType<GridViewRow>(); if (row != null && row.ParentOfType<GridViewRow>() == null) { row.DetailsVisibility = row.DetailsVisibility == System.Windows.Visibility.Visible ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible; } } }If this is not the case, indeed we cannot suggest you a better solution.
Didie
the Telerik team
Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.
This looks perfect. Thanks. Will let you know in case I face any issues.
Cheers!
Ganesh
