This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hello, I'm looking for a way to save the state of the property grid (how property trees are expanded and the last selected property for example). What I would like to achieve is that the property grid should save and restore its state base on the selected object type. It's very annoying for the user all the time having to expand property trees just by the fact the object is selected and unselected. Is there a working example available ?
Thanks Claudio
|
|
|
Hello Claudio, Here is an outline example. Please note that there is very little error checking and I have not attempted to optimise it in any way. Also, this only covers expansion, not selection. We begin by defining a couple of simple classes to record the expansion state: public class NodeState : GridState Now we need, before the selection changes, to record the current expansion status: public void RecordGridStatus(PropertyGrid pg) This is pretty simple stuff: we get a reference to the underlying TreeListView and just walk down its Items hierarchy recording whether the TreeListViewItem for any given item is expanded. We then record that in the _gridStates dictionary against the type of the currently selected object. Once we have changed the selected object, we now need to restore any previous expansion status (in this case, any expansion status associated with the type of the new selected object). However, some care is required here. WPF does not actually create tree view items until they are needed; therefore we need to let the data binding infrastructure finish creating the tree view items at one level before we start expanding them and asking for their children. To do this, we use the WPF dispatcher to defer each level of expansion until the previous one has finished. public void RestoreGridStatus(PropertyGrid pg) Once you have got these functions defined then just call RecordGridStatus() before changing the SelectedObject and RestoreGridStatus() after changing the selected object. (If SelectedObject is databound then we may have to add some events for you -- let us know.) |
|
|
Ivan, sounds good, thank you very much |
|