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
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.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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
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.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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
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?
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