View previous topic :: View next topic |
Author |
Message |
Harri
Joined: 21 Nov 2005 Posts: 13
|
Posted: Tue Mar 28, 2006 6:07 am Post subject: Expand tree to certain items |
|
|
Can you help me with implementing the following requirement :
This is my data-structure, my data structure contains elements that are not to be shown in the tree (this is aranged by overriding the GetChildrenForRow of the ObjectRowBinding):
- Root
- Item A
- Item A1
- ChildToBeShown A1q *
- Item A2
- ChildNotToBeShown A2q
- ChildToBeShown A3q
- Item A3
- ChildToBeShown A3q *
- ChildNotToBeShown A3r *
- Item B
- Item B1
- ChildNotToBeShown B1q
- Item B2
- ChildToBeShown B2q *
- ChildNotToBeShown B2q
- Item B3
- ChildNotToBeShown B3q *
- ChildToBeShown B3q
So, in my virtual tree, when all is expanded it is shown as follows:
- Root
- Item A
- Item A1
- ChildToBeShown A1q *
- Item A2
- ChildToBeShown A3q
- Item A3
- ChildToBeShown A3q *
- Item B
Item B1
- Item B2
- ChildToBeShown B2q *
- Item B3
- ChildToBeShown B3q
When all is Collapsed it is shown as follows:
+ Root
Now, the user clicks a button and wants to expand the tree so that all ChildToBeShown, marked with an asterix(*), are displayed:
- Root
- Item A
- Item A1
- ChildToBeShown A1q *
+ Item A2
- Item A3
- ChildToBeShown A3q *
- Item B
Item B1
- Item B2
- ChildToBeShown B2q *
+ Item B3
I have the collection with all the items that have the * (including the items that do not need to be shown).
- ChildToBeShown A1q *
- ChildToBeShown A3q *
- ChildNotToBeShown A3r *
- ChildToBeShown B2q *
- ChildNotToBeShown B3q *
From here I need to show the tree is shown above.
Could you be so kind to give me some directions/suggestion? |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Tue Mar 28, 2006 9:07 am Post subject: |
|
|
I think the formatting showing your hierarchy got lost so it is a little difficult to be sure about what you asking. But I think what you want is to iterate over your collection something like this:
Code: |
_virtualTree.SuspendLayout();
foreach (Object item in myItems)
{
Row row = _virtualTree.FindRow(item);
if (row != null)
{
row.ExpandAncestors();
}
}
_virtualTree.ResumeLayout();
|
This assumes that you have set up the Parent-Child relationships by setting the ParentProperty in the RowBindings or by handling the GetParent event and so FindRow will be able to locate the row by traversing the relationships. _________________ Infralution Support |
|
Back to top |
|
|
Harri
Joined: 21 Nov 2005 Posts: 13
|
Posted: Tue Mar 28, 2006 9:18 am Post subject: |
|
|
Yep, the formatting is lost,
In your code, the method FindRow is used. However, when my tree is completly collapsed, all my items are not displayed and the FindRow returns null.
I'll try to repost my tree-hierchie with formatting
Code: |
- Root
- Item A
- Item A1
- ChildToBeShown A1q *
- Item A2
- ChildNotToBeShown A2q
- ChildToBeShown A3q
- Item A3
- ChildToBeShown A3q *
- ChildNotToBeShown A3r *
- Item B
- Item B1
- ChildNotToBeShown B1q
- Item B2
- ChildToBeShown B2q *
- ChildNotToBeShown B2q
- Item B3
- ChildNotToBeShown B3q *
- ChildToBeShown B3q
So, in my virtual tree, when all is expanded it is shown as follows:
- Root
- Item A
- Item A1
- ChildToBeShown A1q *
- Item A2
- ChildToBeShown A3q
- Item A3
- ChildToBeShown A3q *
- Item B
Item B1
- Item B2
- ChildToBeShown B2q *
- Item B3
- ChildToBeShown B3q
When all is Collapsed it is shown as follows:
+ Root
Now, the user clicks a button and wants to expand the tree so that all ChildToBeShown, marked with an asterix(*), are displayed:
- Root
- Item A
- Item A1
- ChildToBeShown A1q *
+ Item A2
- Item A3
- ChildToBeShown A3q *
- Item B
Item B1
- Item B2
- ChildToBeShown B2q *
+ Item B3
|
Thank you in advance for your answer. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Tue Mar 28, 2006 10:01 pm Post subject: |
|
|
The reason FindRow returns null is because there is a problem with your Parent-Child relations. If these are setup correctly it will work even when the tree has not been expanded.
FindRow(Object) works by building the path to the row by calling GetParent until it gets to the root row. If you have SuppressErrorMessages set to false (the default) then if FindRow is unable to locate the row it will print diagnostic messages to the Trace (Visual Studio Output) Window to help you work out what the problem might be.
You can alternatively use one of the other overloaded versions of FindRow that take a full path. _________________ Infralution Support |
|
Back to top |
|
|
|