I have a four table dataset that I am binding to my tree. I have the relations set up and the tree displays as I would expect. I had some issues setting a key and tag but put the following code in that seems to have sorted that part out.
void treeDocumentType_InitializeDataNode(object sender, InitializeDataNodeEventArgs e){ switch (e.Node.BandName) { case "tblClass": e.Node.Key = ((DataRowView)e.Node.ListObject)["uidClass"].ToString(); break;
case "relClassMember": e.Node.Key = ((DataRowView)e.Node.ListObject)["uidMember"].ToString(); break;
case "relMemberSummary": e.Node.Key = ((DataRowView)e.Node.ListObject)["uidSummary"].ToString(); break;
case "relSummaryPhrase": e.Node.Key = ((DataRowView)e.Node.ListObject)["uidPhrase"].ToString(); break; }}
I suppose the first question is if this is the accepted way to set those variables or should I be doing something else.
The issue that I am having is reselecting a node after performing an operation. I can easily re-bind the tree which work, but I can't make the previously selected node re-select. I tried using
treeDocumentType.GetNodeByKey(e.MemberId.ToString());
where e.MemberId is the Guid that was previously selected. That result comes back as null. However if I set a breakpoint and then open up the immediate window I can make the following query
?treeDocumentType.Nodes[0].Nodes[0].Key
this will show the correct key. If I then re-execute the GetNodeByKey bit it will work. Is there a better way to do this?
Thanks, I appreciate any insight.
indxlogic said:I suppose the first question is if this is the accepted way to set those variables or should I be doing something else.
This is a good way to do it.
indxlogic said: The issue that I am having is reselecting a node after performing an operation. I can easily re-bind the tree which work, but I can't make the previously selected node re-select. I tried using treeDocumentType.GetNodeByKey(e.MemberId.ToString()); where e.MemberId is the Guid that was previously selected. That result comes back as null. However if I set a breakpoint and then open up the immediate window I can make the following query ?treeDocumentType.Nodes[0].Nodes[0].Key this will show the correct key. If I then re-execute the GetNodeByKey bit it will work. Is there a better way to do this? Thanks, I appreciate any insight.
It's typically best to avoid re-binding the control if you can avoid it. Re-binding means that the whole tree, all the nodes, and all of the ColumnSets are destroyed and a whole new set are created. So this is very inefficient and you will lose the active node, the selected node, the width and position of the columns, etc.
So my first question is - why rebind?
To answer your question, the reason it's not working is that the tree loads the nodes as it needs them. So if you bind the tree and immediately call GetNodeByKey, the node you are looking for probably has not been added to the tree, yet. You can force the tree to load the nodes by looping through the nodes recursively and checking the Count property, but this isn't very efficient.
Mike Saltzman"] So my first question is - why rebind?
That is a great question, and I don't have an answer for it. That is the way we had to do it with our previous tree control. Our previous method was to pull data out of the db, loop through and manually add in nodes. When saving we would write to the database and then clear out the nodes and start over. I agree it is not an effcient way of doing things, but our previous contol was not very useful when it came to binding options.
What would you recommend?