Hi
I want to know how can I retrieve database fields for each level from Web Tree. for example I have a webTree control with 3 levels. This is bound to the database as follows:
dsmain.Tables["BP"].Columns["bp_id"],
dsmain.Relations.Add("SecMR",
dsmain.Tables["MR"].Columns["sec_id"]);
this.treeMain.Levels[0].LevelKeyField = "name";
this.treeMain.Levels[1].LevelKeyField = "name";
this.treeMain.Levels[2].LevelKeyField = "approved_ts";
this.treeMain.Levels[0].LevelImage = "ig_treeNews.gif";
this.treeMain.Levels[0].RelationName = "BPSec";
this.treeMain.Levels[0].ColumnName = "name";
this.treeMain.Levels[1].RelationName = "SecMR";
this.treeMain.Levels[1].ColumnName = "name";
this.treeMain.Levels[2].ColumnName = "approved_ts";
this.treeMain.DataMember = "BP";
this.treeMain.DataSource = dsmain;
this.treeMain.DataBind();
_________________________________________________________
It works fine. So, now for example if I click on the 3rd level in the tree, how do I retrieve all the corresponding values from the tree object? I would need the ID of the first level, ID of the second level, and ID of the third level at a minimum. Can I just use some format like : treeMain.nodes.levels[3].fields["ID"]....... or something similar like that? I am hoping it is this easy. I took a look at the documentation, but couldn't find a clear indication of what objects I would need to get the desired values.
Thanks!
Hello,
Yes, depending on the way the treeview is bound, the DataKey would hold the key to uniquely identify the datasource row and DataPath would be an XPath like path to the node. So it really depends on the way you are databinding the treeview.
Tag is a custom property which can be used to store additional information per node.
What is the DataKey and DataPath used for exactly? I noticed on the nodebound event that I can set e.Node.Tag, e.Node.DataKey, e.Node.DataPath to any values I want. Even though the dataPath is supposed to be readonly! So, I can then set the values to the id's from the dataitem but I was thinking there was a more automatic way of retrieving the current node's row , in the nodeClicked event?
Thanks for the idea.
I was thinking to use the tag property to store the ID's of each level concatenated in a string something like "<1234><653><423>" and I would store those when i create each level. So, then when the user clicks on any node, for example if they were on the third level, they would get the string as above, but say if they clicked on the child node in the 2nd level the tag would be : "<1234><653>", and then on the parent level, the tag would be: "<1234>" But then I couldn't bind it to the database, could I? Would I have to programmatically add the nodes to the tree?
Any ideas on code for that? thanks.
Yes, I see. It is a very good question actually. The problem to face here is that this is a UI control and we try to make it as lightweight as possible and therefore there is no functionality to assign data object with node that will be persisted on postback (similar to the Tag property in WinForms). We do understand that it is sometimes needed to associate node with data, and this is why we have exposed to properties for tree node - DataPath and DataKey that can be used to assign fields from datasource rows to nodes.
Still, I currently am going through the <Level object and do not see a property to map declaratively to DataPath and DataKey.
Maybe you can try using the NodeBound server-side event (fires for each node that is being bound) and map manually with code from DataItem (the object that the node is being bound to) to DataKey / DataPath.
I apologize if this is a bit complicated or hard.
Basically, what I need to do is open the record associated with that node, so if the user double clicks on any particular child node, or just clicks on the child node and presses a button, then I need to open the record associated with that node (so I need parent ID, child ID and grandchild ID to be able to open that record), assuming the user clicks on the grandchild node. All I can seem to retrieve is the 'tag' property but that just gives the text of the node, which is not what I wanted. This is a very standard question that should have a lot of examples on infragistics website or on the web in general, but is strangely non-existant anywhere. A real life example would be if you are in Windows Explorer and you double click on a file within a folder, that is the same idea, so this is a very basic question, which doesn't seem to have any answers anywhere. All the examples fall short of showing what exactly needs to be done, they just show a tree but nothing that is at all practical, that actually performs some real-life action when the user clicks on a node of the tree. Trees are not just for display purposes, they are to be used to show data in a particular organized way, and normally the child nodes are the actual data that needs to be viewed in a format other than a tree, but no one has asked this question on the forums yet??