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.
the examples show msaccess. But, how do we know which code we can remove and still get it to work for a practical database such as SQL server? the help doesn't give any samples, and the samples are not practicle at all. Shouldn't there be complete documentation and samples on how to perform every single method of binding data to the tree control, and all controls for that matter? Of course, the answer is yes, but there is next to no help at all. And, support just gives a little bit of info, but of course there is just way too much information missing.
The database you use shouldn't matter. Once you get the data into an ADO.NET DataSet, how WebTree (or other controls) interact with that DataSet is no different, whether the data came from SQL Server, MS Access, or a method call that never touches a database.
Documentation on binding to a DataSet was removed, primarily because it became so difficult to work with DataSet objects in .NET 2.0 (since you can no longer add components to a webpage at design-time). Information on doing this is still provided in our Knowledge Base, however:HOWTO: Binding [WebTree] to a DataView
If you only have a single table of data with no relations, then you only need to set the Levels[0].ColumnName property; you don't need to set the Levels[0].RelationName if there's no relation to work with.
Since I'm not sure why you'd use WebTree to display flat data, I suspect your "one table" may actually be a self-referencing table. If that's the case, the following Knowledge Base article may help:HOWTO: How to bind the WebTree to a self-referencing table
I've gotten the 3 levels to work. Of course, having three datasets to be combined into one required some extra coding, as follows:
DataSet dsmain = new DataSet();
ds2.Tables[0].TableName = "table2";
dsmain.Merge(ds1.Tables["table1"]);
dsmain.Merge(ds3.Tables["table3"]);
Only then, is the data ready to be bound to the tree, along with setting relations, column names, and indexes.
Help has been great here and by Technical support personnel. I have one other quick question: My tree is now working fine, and bound 3 levels deep to 3 queries. I now want to be able to update the tables (that are bound to the tree control) from another button on the form (where the tree control resides), and have the tree data to be updated after the code updates the database, WITHOUT collapsing the tree, preferrably just adding or removing any nodes depending on how the table is updated. Is there a simple way to do this, or an example? Thank you.
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.
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.
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.
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.