This is a migrated thread and some comments may be shown as answers.

Perserve Row State When Refreshing Data Source

6 Answers 74 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dan Harvey
Top achievements
Rank 2
Dan Harvey asked on 05 Apr 2011, 03:46 PM
Hello,

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

Sort by
0
Rossen Hristov
Telerik team
answered on 05 Apr 2011, 03:58 PM
Hello Dan Harvey,

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.

Greetings,
Ross
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Dan Harvey
Top achievements
Rank 2
answered on 05 Apr 2011, 04:06 PM
So using commands, how do I fire a command when the rowdetails plus/minus button is pressed?

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,
0
Rossen Hristov
Telerik team
answered on 05 Apr 2011, 04:10 PM
Hi Dan Harvey,

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.

Best wishes,
Ross
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Dan Harvey
Top achievements
Rank 2
answered on 05 Apr 2011, 04:19 PM
Ok, how can my viewmodel see this dictionary though?  Will it be in scope if it is declared in the code behind of the xaml?  Because I assume you must handle the RadGridView.RowDetailsVisibilityChanged event in the xaml's code behind.

Thanks!
0
Dan Harvey
Top achievements
Rank 2
answered on 05 Apr 2011, 04:28 PM
Also,

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,
0
Rossen Hristov
Telerik team
answered on 05 Apr 2011, 04:52 PM
Hello Dan Harvey,

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.

All the best, 
Ross
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Dan Harvey
Top achievements
Rank 2
Answers by
Rossen Hristov
Telerik team
Dan Harvey
Top achievements
Rank 2
Share this question
or