How to expand/collapse all the row details in a grid with a GridViewToggleRowDetailsColumn column?

1 Answer 73 Views
GridView
Joao
Top achievements
Rank 1
Joao asked on 28 Sep 2022, 04:18 PM

I have a RadGridView with one of its columns being a GridViewToggleRowDetailsColumn to allow the operator to expand or collapse the selected row details.

Next to the grid I have a checkbox that I want to use to expand/collapse all rows details in a single click if needed.

I’ve managed to partially do it by using the following code, but the collapse doesn’t work unless I disable row virtualization which I cannot.

Does anyone have a solution to this problem?


        private void ToggleAllRowsDetails(object sender, RoutedEventArgs e)
        {
            if(DataContext is MyViewModel vm)
            {
                using (MyGrid.DeferRefresh())
                {
                    if (MyRowDetails.IsChecked.Value)
                    {                       
                        MyGrid.RowDetailsVisibilityMode = GridViewRowDetailsVisibilityMode.Visible;
                    }
                    else
                    {
                        MyGrid.RowDetailsVisibilityMode = GridViewRowDetailsVisibilityMode.Collapsed;                      
                    }
                }
            }
        }

1 Answer, 1 is accepted

Sort by
1
Accepted
Martin Ivanov
Telerik team
answered on 03 Oct 2022, 08:51 AM

Hello Joao,

To achieve your requirement, you can define a new property in your model of the rows and then data bind it to the DetailsVisibility property of GridViewRow. You can do this via the RowStyle property of RadGridView.

public class RowInfo : ViewModelBase
{
	private Visibility detailsVisibility = Visibility.Collapsed;

	public Visibility DetailsVisibility
	{
		get { return detailsVisibility; }
		set { detailsVisibility = value; OnPropertyChanged("DetailsVisibility"); }
	}
	
	// other properties here
}

<telerik:RadGridView.RowStyle>
	<Style TargetType="telerik:GridViewRow">
		<Setter Property="DetailsVisibility" Value="{Binding DetailsVisibility, Mode=TwoWay}"/>
	</Style>
</telerik:RadGridView.RowStyle>

When you need to expand or collapse all row details, you can go through all your items and set their new property.

See this approach shown also in the attached project. I hope it helps.

Regards,
Martin Ivanov
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
Joao
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or