Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Hide nodes in the tree.

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support
View previous topic :: View next topic  
Author Message
JohnSummit



Joined: 10 Apr 2008
Posts: 32

PostPosted: Sun Feb 01, 2009 8:42 am    Post subject: Hide nodes in the tree. Reply with quote

I have an application where i add thousands and thousands of nodes in the tree in an hierarchical fashion. All data is added to the tree as it becomes available. I'm using UpdateRows to refresh the tree with new data every second. This works very well. Note that i am not using the virtual feature of the tree.

I now want to filter out some nodes in the tree on the fly without having to search through the tree. I'm thinking of keeping references to all nodes of a certain type in an ArrayList and then, later on as needed, simply make them 'not visible' in the tree. This should have the effect of immediately hiding/showing the nodes.

Is there some way to 'hide' nodes in the tree to accomplish the above?
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Sun Feb 01, 2009 10:46 pm    Post subject: Reply with quote

There is isn't a Row.Visible property because it would ruin Virtual Trees performance. If rows could potentially be invisible then Virtual Tree would have no way of calculating how many visible children a row had (and therefore the required scrolling parameters) without first loading each of the children and calling the RowBinding.RowVisible property.

If you are willing to take that performance hit then it is relatively easy to handle the GetChildren event (or override the GetChildrenForRow method) and simply copy the originally children collection into a new list omitting those items that should be invisible.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
JohnSummit



Joined: 10 Apr 2008
Posts: 32

PostPosted: Mon Feb 02, 2009 2:09 am    Post subject: Reply with quote

Infralution wrote:
There is isn't a Row.Visible property because it would ruin Virtual Trees performance. If rows could potentially be invisible then Virtual Tree would have no way of calculating how many visible children a row had (and therefore the required scrolling parameters) without first loading each of the children and calling the RowBinding.RowVisible property.


In my case, i have already loaded all children so i would think that in theory it would be feasible to have the tree control simply not show certain nodes. One idea that comes to mind would be to simply not add (or remove) a row binding for a particular class. It would be very nice to be able to simply remove rowbindings for a certain node class and have the tree remove those nodes automatically. Currently, the tree instead shows the type name of the node if it does not have a rowbinding added (instead of actually hiding the node).

Again, the tree is fully populated (including all child nodes) when i want to hide/show certain nodes. It will get very messy if i have to keep track of the exact location of a certain node type in the tree because i will have to remember where in the tree the removed nodes were stored so i can later add them back when the user un-filters the tree view.

I also assume that searching the tree for a certain node type will be very slow?
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Mon Feb 02, 2009 2:37 am    Post subject: Reply with quote

Quote:
In my case, i have already loaded all children so i would think that in theory it would be feasible to have the tree control simply not show certain nodes.


Iterating through every child to see if it is visible (and so determine the number of visible children for scrolling purposes) may not affect your performance too much if you don't have really large numbers of child nodes and the data is already loaded in memory (although it will certainly still have some perfomance affect) - but this would definitely have a very adverse affect on applications that have very large numbers of child nodes and/or do not load data until it is requested. This is precisely the type of application that Virtual Tree is aimed at.

Quote:
One idea that comes to mind would be to simply not add (or remove) a row binding for a particular class. It would be very nice to be able to simply remove nodes that are of a certain class and have the tree remove those nodes automatically. Currently, the tree instead shows the type name of the node if it does not have a rowbinding added (instead of actually hiding the node).


This wouldn't overcome the primary issue with doing this ie that the tree would have to iterate through every child data node to determine it's visibility.

If you do want this type of feature and the performance impact does not concern you then you can implement it as noted previously. For instance if as you mentioned you just want to hide data items of a particular type you could do it like this:

Code:
private void _virtualTree_GetChildren(object sender, GetChildrenEventArgs e)
{
    // use the default binding to get all the children
    //
    RowBinding binding = _virtualTree.GetRowBinding(e.Row);
    IList children = binding.GetChildrenForRow(e.Row);

    // return a list containing only the children you want to be visible
    //
    ArrayList visibleChildren = new ArrayList();
    foreach (object child in children)
    {
        if (!(child is SomeTypeToHide))
        {
            visibleChildren.Add(child);
        }
    }
    e.Children = visibleChildren;
}

_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
JohnSummit



Joined: 10 Apr 2008
Posts: 32

PostPosted: Mon Feb 02, 2009 5:50 am    Post subject: Reply with quote

My tree may very well contain many hundreds of thousands of nodes so i need to avoid any parsing of the tree or else hiding/showing nodes will be too slow to be useful.

If i bought the source code, would it be possible to hide a node without actually removing it from the tree? If nodes are removed i would need to save both the parent node as well as the child node index or else i would not be able to know in which child collection to insert the node again when a specific node type is 'un-hidden'. This would quickly become very messy.

Ideally, i would like to have an external ArrayList that contains references to all nodes of a particular type (populated when nodes are added to the tree). I would then be able to iterate through all ArrayList members and directly show/hide the nodes that they are referencing. Ideally, then, the tree would 'magically' show/hide the nodes. I would expect the tree to lose track of the current position but this should not be too hard to handle (by scrolling the nearby nodes into scope).

Possible?
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Mon Feb 02, 2009 6:28 am    Post subject: Reply with quote

Quote:
If i bought the source code, would it be possible to hide a node without actually removing it from the tree? If nodes are removed i would need to save both the parent node as well as the child node index or else i would not be able to know in which child collection to insert the node again when a specific node type is 'un-hidden'.


Virtual Tree is quite unlike other trees you may have used. Virtual Tree is completely data driven and does not maintain its own permanent internal representation of your data structure which you need to keep in sync with your data. This means that even though your data hierarchy may contain thousands of items Virtual Tree only maintains a "node" (actually called a Row in VirtualTree) representation for those data items which are currently displayed or expanded. This greatly reduces the memory footprint of Virtual Tree and eliminates the need to sync between your data model and the tree model - since Virtual Tree always displays your data model.

So to remove node(s) from the Virtual Tree all you need to do is change the data that you provide Virtual Tree. You can do this programatically to temporarily hide nodes by handling the GetChildren event as I showed in the last post. You then don't have to worry about fixing up Virtual Tree's internal representation (in fact you can't) because Virtual Tree will do this automatically for you. All you need to do if your visibility conditions change is to call VirtualTree.UpdateRows. This will force VirtualTree to update its internal model and call GetChildren - which will then return to virtual tree the new data items it should be displaying.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
JohnSummit



Joined: 10 Apr 2008
Posts: 32

PostPosted: Mon Feb 02, 2009 7:45 am    Post subject: Reply with quote

Thank you for your excellent support. I will experiment and see what i can do.
Back to top
View user's profile Send private message
JohnSummit2



Joined: 18 Jan 2011
Posts: 12

PostPosted: Thu Dec 19, 2013 10:11 pm    Post subject: GetChildren for root node not working properly? Reply with quote

I finally got around to trying using the GetChildren event to return the visible subset of child rows for a particular row. As explained earlier, I have a need to hide/show certain rows in the tree on the fly. It is not working properly.

I'm finding that the GetChildren event is called only once for the root row. The event handler filters out the hidden rows and only returns an ArrayList that contains the visible rows, per your suggestion. I have found, however, that the VirtualTree control only updates the *visible* rows from my ArrayList - other rows not visible unless the view is scrolled down will *not* be updated from the root row child list I returned from the GetChildren event handler. This has the effect that rows that should be hidden are shown when the tree is scrolled down vertically.

It seems the issue may be one of caching? I have set "virtualTree1.EnableRowCaching = false" as well as called "ClearCachedRowBindings(); ClearCachedRowData(); and ReindexRows();" without managing to have the VirtualTree use the root node child data returned from the GetChildren event handler for the rows that are not visible at the time UpdateRows is called.

Note that GetChildren is only called *once* for the root row after my application calls UpdateRows. Also note that the behavior works correctly for child nodes under the root row as the tree is scrolled down to reveal new rows. GetChildren will be called on-demand for these child nodes and the hide/show will work for the 3rd level rows.

I have confirmed that the behavior is the same in 3.11 as in 4.8.1.
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Thu Dec 19, 2013 11:56 pm    Post subject: Reply with quote

Quote:
I have found, however, that the VirtualTree control only updates the *visible* rows from my ArrayList - other rows not visible unless the view is scrolled down will *not* be updated from the root row child list I returned from the GetChildren event handler.


OK I'm not really sure what you mean by this. The GetChildren event should return the list of all items that you want displayed (not just those currently visible without scrolling). Can you post some code from your GetChildren event to help understand what you are doing.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
JohnSummit2



Joined: 18 Jan 2011
Posts: 12

PostPosted: Fri Dec 20, 2013 12:55 am    Post subject: Reply with quote

Please disregard. After some hours of debugging I actually found that the filtering code was incorrect! My GetChildren event handler actually returned child nodes that were suppose to be filtered. The VT works correctly.

Thanks for your quick response, though.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group