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

[Solved] Expand/Collapse All RowDetails

7 Answers 501 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.
Doug
Top achievements
Rank 1
Doug asked on 17 Nov 2011, 07:38 PM
I have a RadGridView that is not using groups or heirarchies. It just contains items and has a RowDetailsTemplate defined with a ToggleRowDetailsColumn as well.

I am trying to add a button outside of the RadGridView that espands and collapses all the rowdetails in the grid when clicked.

I can get the rows to expand by setting the following:

myGrid.RowDetailsVisibilityMode = Telerik.Windows.Controls.GridView.GridViewRowDetailsVisibilityMode.Visible;

However setting the above property to Collapsed doesn't seem to collapse the details views again.

Is there something I'm missing to be able to collapse the RadGridView's RowDetails?

7 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 18 Nov 2011, 10:19 AM
Hello Doug,

Actually, the two concepts - using GridViewToggleRowDetailsColumn and setting RowDetailsVisibilityMode - are quite incompatible. You can work with one of them, but not with the two simultaneously. 
Let me know try to explain the idea. If you set RowDetailsVisibilityMode to "Visible", but you collapse one of the rows through the toggle button - which should be respected - that all row details are visible or that one of them is collapsed. Another example will be with VisibleWhenSelected - what if you expand a row through the toggle button, but the corresponding item is not selected - which one should be respected ?
That is why you should use only of the approaches.
If you decide on working with RowDetailsVisibilityMode property without the toggle button column, the approach you choose will work correctly and the details will be expanded and collapsed.
Choosing the second approach - with GridViewToggleRowDetailsColumn will be a bit more complicated. Since only the visible elements are created, you will have to listen for the RowLoaded event for example and once a row is visualized to collapse/ expand its RowDetails.

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Doug
Top achievements
Rank 1
answered on 21 Nov 2011, 03:39 PM
Is there an example of a Gridview that uses both the GridViewToggleRowDetailsColumn and has an external expand/collapse all button?

Is there anyway to manually loop through the rows and programatically recreate the user clicking on the expand button that we could utilize?

Any help is very much appreciated!

Thanks,

Doug
0
Accepted
Maya
Telerik team
answered on 22 Nov 2011, 08:57 AM
Hi Doug,

You can try to expand all row details of the visible rows and update the DetailsVisibility property during the RowLoaded event. I am attaching a sample project illustrating the suggested approach.
 

Best wishes,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Doug
Top achievements
Rank 1
answered on 22 Nov 2011, 03:53 PM
That's exactly what I was looking for. Thanks so much!
0
Ubuntu
Top achievements
Rank 1
answered on 26 Apr 2013, 12:27 PM
Dear Maya,

    Is it possible to do this through a property on the business object or through binding style (VM) and not through the code behind.

Best regards
0
Billy
Top achievements
Rank 1
answered on 18 Jul 2019, 09:05 PM

My need is a little different. I have a RadGridView that expands the items to a RowDetailsTemplate using the GridViewToggleRowDetailsColumn item.

This allows for multiple rows to be expanded at once, which when editing details from each row can cause state and modeling problems. I just need to only allow one item to be expanded at once. 

Example: User expands Row1, and then expands Row2, I need to collapse Row1 and then expand Row2.

Is there a way to do this?

0
Dilyan Traykov
Telerik team
answered on 23 Jul 2019, 10:37 AM
Hello Billy,

I've prepared a small sample project demonstrating how to achieve your requirement by handling the RowDetailsVisibilityChanged event. Here's the code of interest:

private object expandedItem = null;
private void ClubsGrid_RowDetailsVisibilityChanged(object sender, GridViewRowDetailsEventArgs e)
{
    if (e.Visibility == Visibility.Visible)
    {
        this.expandedItem = e.Row.DataContext;
        var rows = this.clubsGrid.ChildrenOfType<GridViewRow>();
        foreach (GridViewRow row in rows)
        {
            if (row.DataContext != expandedItem)
            {
                row.DetailsVisibility = Visibility.Collapsed;
            }
        }
    }
}

Please note, however, if you're using the control's UI virtualization mechanism you may also want to handle the rows' RowLoaded and RowUnloaded events to control the DetailsVisibility of the rows when they enter/exit the viewport. This, however, depends on whether you want the details to be collapsed once they exit the viewport.

I hope you find this helpful. Do let me know if I can further assist you in any way.

Regards,
Dilyan Traykov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Doug
Top achievements
Rank 1
Answers by
Maya
Telerik team
Doug
Top achievements
Rank 1
Ubuntu
Top achievements
Rank 1
Billy
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Share this question
or