Hi, I'm having a problem with XamDataTree, that has already been reported on stackoverflow: http://stackoverflow.com/questions/6295882/programmatically-activate-a-node-in-infragistics-xamdatatree
I'll simply cut&paste the question on stackoverflow, since it exactly matches my situation. Do you have any suggestion? Thanks a lot, cheers!
--
I'm using Infragistics NetAdvantage for Win Client 2010 Vol. 3.
I made a WPF User Control that shows some nested items using a XamDataTree control. Tree nodes are loaded from a binded Observable item collection:
MenuNode menuTree = getMenuTree(true); ObservableCollection<MenuNode> menuNodes = menuTree.children; this.treeFP.ItemsSource = menuNodes;
I couldn't find a suitable tree method that activates a node based on certain property (eg. a key?). So I created a method that loops through the whole tree, until it finds the correct node to activate:
void selectNode(XamDataTreeNodesCollection nodes, string nodeKey)
I then called this method in this way:
selectNode(theTree.Nodes, "KEYTOSELECT");
It turned out that theTree.Nodes collection is empty! Why? Probably because items source is binded? If this behaviour is correct (?), is there another way to activate a single node?
The only thing I could think of without seeing it happen is that you are calling it prior to the loaded event of the tree. The Data won't be bound until the tree is loaded.
Hi Darrel,
I initialize my tree in the User Control's constructor, after InitializeComponent() call. And then, I try to activate a single node. Data is correctly bound (I think), because I can see my nodes on tree.
The problem affects only the underlying object model: Nodes collection is empty, while tree is full of nodes! Very strange...
Thank you for your reply. Bye!
Well the fact that the tree renders means nodes were created, you shoudl probably attach a loaded event hander to the tree and do the activation there.
Just a follow-up to check if others are having my strange behaviour.
If I first modify my menuTree collection (by removing and adding child nodes), and then I bind it to XamDataTree, selectNode() method doesn't succeed. Tree's ActiveNode is set to the right node, but XamDataTree fails in expanding parent nodes to bring it into view. Eg. if I have this tree:
- A
A1
A1a
A1b
A2
- B
B1
and I want to select "A1a", my tree shows "A" expanded and "A1" collapsed. And then "A1a" is not displayed, since its parent is collapsed.
The problem is the call to ObservableCollection.Remove() method. If I comment out this line, everything works fine (but obviously after a few operation my nodes gets duplicated...).
I've found many 'ObservableCollection Remove not working' posts on the net, but none seems to clarify the issue I'm having...
Thanks again, bye!
Wow! I moved my node activation inside tree_Loaded event handler and it works! :)
Thank you! Bye!