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.
Subscribe to be the first to get our expert-written articles and tutorials for developers!
All fields are required
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.