View previous topic :: View next topic |
Author |
Message |
MHB
Joined: 04 Apr 2005 Posts: 69
|
Posted: Wed Apr 27, 2005 12:13 pm Post subject: Behaviour of Row references when child lists change |
|
|
How are rows handled when child lists change?
My situation is this: I have a row A with two children B and C:
A
|-- B
|-- C
I now save references to rows B and C. Then the object in A's child list (which implements IBindingList) that corresponds to B is removed. Is the reference to C now invalidated? Maybe the row is replaced by a new one? Whichever, the problem is that C.Item is now null. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Wed Apr 27, 2005 11:26 pm Post subject: |
|
|
The section "Working with Rows" in the task based help gives some guidance on this.
Quote: | The lifetime of Row objects is managed by the VirtualTree. In general you should not hold onto references to rows outside of the current call frame (ie don't store row references in member or static variables) because the VirtualTree may decide to dispose of the Row object if it is no longer required. Calling the UpdateRows method will force the VirtualTree to rebuild the row objects from the DataSource and dump any cached rows which are no longer required to support the current display. |
_________________ Infralution Support |
|
Back to top |
|
|
MHB
Joined: 04 Apr 2005 Posts: 69
|
Posted: Fri Apr 29, 2005 9:39 am Post subject: |
|
|
Well, my problem occurs when all of the above is executed inside a method invoked by a user action, so the references are local. I think the problem is that what you are referring to is methods called by the thread(s) that the tree itself creates. Hence, I can never save references from the outside? |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sat Apr 30, 2005 8:39 am Post subject: |
|
|
In general get the reference to the row object just before you need to use it and you will be fine. If you obtain a reference to a row object then call VirtualTree.UpdateRows then your row reference will have been disposed. Similarly if you obtain a row reference then change a bound data source you may find that the tree has disposed of the rows. _________________ Infralution Support |
|
Back to top |
|
|
|