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
|
How can I expand all/collapse all nodes in the Multicolumn Tree View control. My setup for the toggle buttons is the same as what is in your Elements Example for the MulticolumnTreeViewStyling. The items in the control are not TreeViewItems but are "Person" items therefore they do not have an IsExpanded field.
Thanks, |
|
|
Hello Jessica You can access the MulticolumnTreeViewItem objects using the ItemContainerGenerator property. Here is some example code that simply expands all the items: (mctv is a MulticolumnTreeView instance)
private void OpenMulticolumnItems() private void OpenMulticolumnItems(MulticolumnTreeViewItem item) The first method iterates through the items in the MulticolumnTreeView itself. The second method is called by the first method and is used for recursively expanding the nested children. The ContainerFromItem method on the ItemContainerGenerator gets the MulticolumnTreeViewItem for the given data object. Let us know how it goes |
|
|
Hi Jason I have a MulticolumnTreeView and when I use the code you listed by calling OpenMultiColumnItems() only the first level expands. If I call OpenMultiColumnItems() again the second level expands and if I call it a third time the code crashes. I was expecting the recursive functions to open all levels the first time I call the OpenMultiColumnItems() function. Regards Bo Lovmand |
|
|
I am seeing the same behavior except that mine does not crash. Each time I call the OpenMultiColumnItems the tree expands to an additional level deeper. |
|
|
Hello Where are you calling the method from? The constructor of the window?, or some kind of button click event? From a button event it should work fine. If you are calling it from the application window constructor you will want to call the first method through a dispatcher using DispatcherPriority.Loaded. The ItemContainerGenerator.ContainerFromItem method can only find the UI elements after the control has been loaded. Other than that, every thing is working fine at my end. All levels get expanded in one method call. If it still doesn't work, try using a dispatcher to make the recursive calls, again you should use the Loaded DispatcherPriority here. Let me know how it goes |
|
|
I have attached the multicolumntreeview sample that I modified to have a expand button. I am calling the expand method through the button. Every time you press the button the tree expands one level deeper. I tried putting the dispatcher with the load argument but it didn't seem to work. Thanks, Jessica |
|
|
I was able to figure out the Dispatcher method suggestion you gave. I had to add it to both recursive calls in order to get the tree to fully expand the first time from the button click event handler. I am pasting the code in case some wants to see it. Thanks for your help Jason !
private void Button_Click(object sender, RoutedEventArgs e) { OpenMulticolumnItems();
} private void OpenMulticolumnItems() { foreach (object o in mctv.ItemsSource) { object container = mctv.ItemContainerGenerator.ContainerFromItem(o); MulticolumnTreeViewItem item = container as MulticolumnTreeViewItem; if (item != null) { item.IsExpanded = true; Dispatcher.Invoke(new System.Action<MulticolumnTreeViewItem>(OpenMulticolumnItems), DispatcherPriority.Loaded, item); // OpenMulticolumnItems(item); } } } private void OpenMulticolumnItems(MulticolumnTreeViewItem item) { foreach (object o in item.ItemsSource) { object container = item.ItemContainerGenerator.ContainerFromItem(o); MulticolumnTreeViewItem child = container as MulticolumnTreeViewItem; if (child != null) { child.IsExpanded = true; Dispatcher.Invoke(new System.Action<MulticolumnTreeViewItem>(OpenMulticolumnItems), DispatcherPriority.Loaded, child); //OpenMulticolumnItems(child); } } } |
|
|
Thanks Jessica It seems that the reason why it was working at my end without the dispacther calls is because I was using the OfficeBlue theme. This theme is set up in a different way to include animations which also results in the rows being loaded as soon as they expand. Good to hear you've got it all working with the dispatchers. - Jason |
|