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

How to collapse RadGridView RowDetailsTemplate

3 Answers 111 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 26 Mar 2012, 02:06 PM
I currently have a RadGridView with a RowDetailsTemplate that expands when a row is selected by using RowDetailsVisibilityMode="VisibleWhenSelected".  When I click on another row, the previously selected row collapses and the new row expands like I want.  However, how do I make the selected row collapse when I click on the selected row a second time instead of clicking on a different row?  I'm basically trying to get back to where all rows are collapsed.  I am not using the '+' button control so it will have to respond to a click anywhere on the selected row.  Thanks.

3 Answers, 1 is accepted

Sort by
0
Accepted
Dimitrina
Telerik team
answered on 27 Mar 2012, 10:13 AM
Hello,

I would suggest you to clear the selection when the SelectedRow is clicked again. That way the RowDetails will be collapsed back.

A sample implementation would look like so:

{
    public MainWindow()
    {
        InitializeComponent();
        this.clubsGrid.CanUserSelect = false;
        this.AddHandler(FrameworkElement.MouseDownEvent, new System.Windows.Input.MouseButtonEventHandler(OnMouseDown), true);
    }
 
    private void OnMouseDown(object sender, MouseButtonEventArgs e)
    {
        var s = e.OriginalSource as FrameworkElement;
        var parentRow = s.ParentOfType<GridViewRow>();
        if (parentRow != null )
        {
            parentRow.IsSelected = !parentRow.IsSelected;
        }
    }

I hope that this is helpful.

All the best,
Didie
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Steve
Top achievements
Rank 1
answered on 27 Mar 2012, 01:31 PM
Worked perfectly.  Thanks!
0
Rossen Hristov
Telerik team
answered on 27 Mar 2012, 01:35 PM
Hi,

CTRL+Click should also deselect a selected row like in all other windows applications. Just an idea.

Regards,
Ross
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
GridView
Asked by
Steve
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Steve
Top achievements
Rank 1
Rossen Hristov
Telerik team
Share this question
or