Reputation: 11010
I need a treeview structure like
Accounts-->Kmart-->California-->Stockton CA 95207
-->Oakdale, CA 95361
from this table
SCID SCEID SCElement ParentID Parent SalesChannelName
67 27 Account 0 Root Kmart
71 28 State 67 KMart California
72 29 Store 71 California Stockton CA 95207
74 29 Store 71 California Oakdale, CA 95361
i tried a sample from this link http://aspalliance.com/732. It is working fine.But i dont know how to (write a query to) form a tree structure from this table in that sample code..Any suggestion?
Upvotes: 0
Views: 1351
Reputation: 8337
Fill the data from the table two times with different tablenames.
Ex:
da.Fill(ds,"Table1");
da.Fill(ds,"Table2");
Now add a data relation in the dataset with the ID from the Table1 and ParentId from Table2
Now Bind to the treeview
Below link will help you.
http://joshsmithonwpf.wordpress.com/2007/05/05/binding-a-treeview-to-a-dataset/
This uses two tables from DB. But you can use the same table twice with small change in the SQL query
Upvotes: 1
Reputation: 1876
In order to 'bind' data to a treeview, it must be in the correct format for the treeview to digest. That is it must apply the IHierarchicalDataSource interface such as a formatted XML Document, etc.
Unfortunately when you grab your data from the database it is not going to be hierarchically formatted leaving you with two options...
HTH
Upvotes: 1