I am using MVVM so I have a property in my view model called "AllClasses" which my gridview's (dgClasses) itemsource property is set to. Each row has a rowDetailsTemplate, so they can be expanded. I want to be able to perserve this expansion when I refresh my data source (AllClasses property is set again).
I wasn't able to find too much in the forums about this.
Please advise.
Thanks,
6 Answers, 1 is accepted
When the grid is re-bound everything is re-created from scratch and it cannot "remember" anything.
In case you don't have row virtualization turned on (i.e. all of the rows are realized), the only way you can do this would be to record which items had their row details expanded in some kind of list or dictionary, then rebind the grid, and go over all items that you recorded and expand their row details by hand.
This of course will be possible if the old items correspond to the new items, i.e. they are the same instances. Or if you have some other logic to allow you to decide which items should have their row details expanded.
In case you have row virtualization turned on, I am afraid that you cannot do this.
I hope this helps.
Ross
the Telerik team
I figured if I could have a command fire every time the plus/minus button is pressed I could then add that row to a dictionary.
Thanks,
The GridViewRow class has a property called DetailsVisibility. It contains the visibility of the row details. In fact this property is bound to the toggle button IsExpanded state. But you will not need to use it directly.
You can attach to RadGridView.RowDetailsVisibilityChanged event and if the row details are expanded -- add the respective data item to the dictionary. If they are collapsed -- remove the data item from the dictionary. The actual data item (i.e. business object) can be found in e.Row.DataContext.
I hope this helps.
Ross
the Telerik team
Thanks!
how can my view model tell the radgrid to expand these rows after a refresh? All it knows about is the collection that the grid view is bound too. It can't see the data grid (dgClasses).
Thanks,
Then I guess that you can't do what you are trying to do. If you can't see the data grid, you can't tell it what to do.
In other words, saving and restoring the details visibility from a view model is not possible. You are trying to do something that is deeply connected with the view (part of the UI) from your view model. I don't think you can do that.
I hope this helps.
Ross
the Telerik team