View previous topic :: View next topic |
Author |
Message |
Hvid Guest
|
Posted: Wed Aug 16, 2006 8:37 am Post subject: Selecting an item deep in the tree structure |
|
|
Hi.
I'm using your tree view to display fairly large quantities of items (100.000+). I'm using standard data binding (GetParent, GetChildren, GetCellData, GetRowData events).
Given any object in the structure the tree is databinding I would like to be able to select and show that item in the tree view. Essentially I know the id of the item I want to select, so I am able to load this item out of the structure the tree is databinding. However, when I try to databind this particular item the treeview will only display this particular item, and not the parent items that this item is nested below. When debugging I can see that the GetParent event is called on the item, and all the parent items are retrieved, but they are not displayed in the treeview?
Illustration:
---A
---B
---C
1) retrieve C
2) databind C
4) debugging GetParent event handler shows me that B and C are retrieved and set in the event handler.
5) Observed result:
---C (Root item)
6) Expected result
---A
---B
---C (selected)
Any ideas? |
|
Back to top |
|
|
Guest
|
Posted: Wed Aug 16, 2006 8:46 am Post subject: |
|
|
Update.
My illustrations had all their spaces removed so I'm redoing those for better understanding:
Illustration:
A
---B
|||---C
5) Observed result:
C (Root item)
6) Expected result
A
---B
|||---C (selected) |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Wed Aug 16, 2006 10:21 am Post subject: |
|
|
I think you may be confusing setting the datasource with selection - but I'm not entirely sure because I'm not sure what you mean by step 2) below.
Quote: | 1) retrieve C
2) databind C
4) debugging GetParent event handler shows me that B and C are retrieved and set in the event handler |
If you mean something like
virtualTree.DataSource = C
Then the result you got is exactly what I would expect. The data source will always be the root item of the tree. To set the selected item you need to use virtualTree.SelectedRow or SelectedItem. To be able to use SelectedItem each item can only appear once in the hierarchy and GetParent must return the parent item (or null for the root item). _________________ Infralution Support |
|
Back to top |
|
|
Hvid Guest
|
Posted: Wed Aug 16, 2006 10:29 am Post subject: |
|
|
Hi.
I originally wanted to use .SelectedItem and set it to the object I wanted to select. The problem is these objects don't exist until they are databound meaning they are IO loaded dynamically as the tree expands. The structure I am databinding against is stored on the disk with a lightweight id based index on top of it. Whenever I retrieve an item it will be a different object than last time - therefore .SelectedItem doesn't seem to work. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Wed Aug 16, 2006 10:16 pm Post subject: |
|
|
You can override the Equals() and the GetHashCode() methods for your class so that instances that represent the same underlying object on disk will be treated as the same object.
Virtual Tree uses the IList.IndexOf() and IList.Contains() methods to locate the row for a given domain data item. For nearly all list implementations these rely on the object.Equals() and GetHashCode() methods - so overriding the Equals and GetHashCode methods generally works. If this isn't possible however you could alternatively create a list implementation that implements the IndexOf and Contains methods so that they are based on the underlying object identity. _________________ Infralution Support |
|
Back to top |
|
|
|