This is a migrated thread and some comments may be shown as answers.

Expand row details on clicking anywhere on the row

12 Answers 180 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ganesh Shivshankar
Top achievements
Rank 1
Ganesh Shivshankar asked on 18 Sep 2012, 06:49 AM
Hi,

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

Sort by
0
Ganesh Shivshankar
Top achievements
Rank 1
answered on 18 Sep 2012, 12:16 PM
Apparently this seems to work, but not sure if it is the best way to do it. Need to do the below in the SelectionChanged event of the GridView. I'm setting the SelectItem to null so that it triggers the selectionchanged again when again clicking the selected row.

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
0
Dimitrina
Telerik team
answered on 19 Sep 2012, 11:45 AM
Hello 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.

0
Ganesh Shivshankar
Top achievements
Rank 1
answered on 20 Sep 2012, 04:38 AM
Thanks Didie. 

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
0
Dimitrina
Telerik team
answered on 20 Sep 2012, 06:20 AM
Hello 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);
 

All the best,
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.

0
Ganesh Shivshankar
Top achievements
Rank 1
answered on 20 Sep 2012, 06:38 AM
Didie,

Is this not same as doing?

clubGrid.MouseLeftButtonDown += OnMouseLeftButtonDown;
0
Vlad
Telerik team
answered on 20 Sep 2012, 06:43 AM
Hello,

 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.

0
Ganesh Shivshankar
Top achievements
Rank 1
answered on 20 Sep 2012, 07:01 AM
Hi Vlad,

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
0
Dimitrina
Telerik team
answered on 20 Sep 2012, 07:06 AM
Hi,

 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;
     }
}

All the best,
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.

0
Ganesh Shivshankar
Top achievements
Rank 1
answered on 20 Sep 2012, 07:11 AM
Hi Didie,

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.
0
Ganesh Shivshankar
Top achievements
Rank 1
answered on 20 Sep 2012, 08:27 AM
Hi Didie,

Looking at my scenario it doesnt seem possible to achieve the behavior i want?

Ganesh
0
Dimitrina
Telerik team
answered on 20 Sep 2012, 11:44 AM
Hi,

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. 

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.

0
Ganesh Shivshankar
Top achievements
Rank 1
answered on 20 Sep 2012, 11:50 AM
Hi Didie,

This looks perfect. Thanks. Will let you know in case I face any issues.

Cheers!
Ganesh
Tags
GridView
Asked by
Ganesh Shivshankar
Top achievements
Rank 1
Answers by
Ganesh Shivshankar
Top achievements
Rank 1
Dimitrina
Telerik team
Vlad
Telerik team
Share this question
or