Hi all. Is there a simple example for binding a dataset with only one table to the tree control? I already saw the sample code for the infragistics online samples, but that is for 3 tables, and I'm wondering what are the minimum code needed. Thanx.
You would have to programmatically add a DataRelation between your parent DataTable and child DataTable. Without a DataRelation, WebTree would have no way to determine how items in the two tables are meant to relate to each other.
That's what I was thinking as well. However, would I have to hardcode a 'relation' field in the hardcoded parent table to be able to have a relation between the parent and child tables? As, there is no real relationship between the hardcoded text and the child tables. I also noticed that there must be a relationship between any tables you want to display as subnodes, otherwise they won't display on the tree.
The simplest option I can think of is to first fetch the data for your child nodes from your database, then programmatically add a DataTable to the resulting DataSet to represent your parent nodes, along with a DataRelation to link your new table to the DataTable you want to represent the first child nodes. From there, you'd databind the DataSet to WebTree as if all the data had come from the database in the first place.
Ok. I've scrapped that idea, as it doesn't seem to be that important to the users to have nodes to be updated without re-opening the tree (at least so far.) My next question is: I now want to be able to mix and match both hardcoded Nodes and nodes that are from a database. I'm not so sure that databinding is the way to go now. For example First level would be hardcoded and would always be present (so The top level would have two 'hardcoded so to speak' nodes which are "accepted items" and "pending items". so all subnodes would of course be 'below' these two hardcoded nodes. But, based on the examples, and docs, it seems that I still can only use one dataset to bind to the tree. But, having 2 nodes that are not databound above all the rest of the nodes would seem to suggest use of 2 datasets, as I tried one dataset hoping it would just be able to bind to level 1, but of course, it doesn't show up. Would you have any suggestions? And, examples would be great. Thank you again Vince.
This isn't a simple process, and I am not able to find any specific samples. From a theoretical standpoint, there are at least two possible approaches to do this.
One way is to listen to the change events on your data source, so that you can identify which data row has changed (whether modified, inserted, or deleted). For insertion, you can find the node in the WebTree that corresponds to the parent data row, create a new node with your new data, and insert this as a child node. For modification or deletion, you can find the node in the WebTree that corresponds to the data row you changed, and either update or remove that node accordingly. You'll need some way to uniquely identify your nodes based on information you can get from your underlying data.
Another way is to re-bind the tree to your updated data, but to instead keep track of which nodes were expanded before you bind and to re-expand those nodes afterwards.