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)
   3: {
   4: if (e.Visibility == System.Windows.Visibility.Visible)
   5:     {
   6: if (lastExpandedRow != null)
   7:         {
   8:             lastExpandedRow.DetailsVisibility = System.Windows.Visibility.Collapsed;
   9:         }
  11:         lastExpandedRow = e.Row;
  12:     }
  13: }

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.

Related Posts


Comments are disabled in preview mode.