If you are familiar with the Row Details feature of RadGridView, you probably have used the VisibleWhenSelected mode in the beginning. In case you have not, you should definitely check out the online example of Row Details.
A couple of months after the Row Details debut, we introduced a new type of column called GridViewToggleRowDetailsColumn, which does exactly what its names says – it provides and easy and fast way of toggling the details visibility of individual rows.
Now, what if you are using this specialized column, but want to achieve a VisibleWhenSelected-like behavior. Let’s see how to hide the previous row details when you expand a new row details through the toggle button. It is really a matter of a dozen lines of code:
1: GridViewRow lastExpandedRow;
2: void OnRowDetailsVisibilityChanged(object sender, Telerik.Windows.Controls.GridView.GridViewRowDetailsEventArgs e)
4: if (e.Visibility == System.Windows.Visibility.Visible)
6: if (lastExpandedRow != null)
8: lastExpandedRow.DetailsVisibility = System.Windows.Visibility.Collapsed;
11: lastExpandedRow = e.Row;
We simply have to store a reference to the last row that had its details visible and hide them when a new row is showing its details.
Below you can see how clicking on a plus sign hides the last visible row details:
Here is the full source code of the above sample.
Copyright © 2017, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.