Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Hi,

Can't we show tree view structure in DatagridView using C#?

DataSet ds0 = GetDB1(db1);
DataSet ds1 = GetDB1(db2);
DataSet ds2 = GetDB1(db3);

C#
dgDB1.DataSource = ds0.Tables[0];
               dgDB1.Columns[1].Visible = false;
               lbldb1.Text = "Database: " + ds0.Tables[0].Rows[0][1].ToString();



when i take TreeView control i dont get Datasource for that.
so to show all objects of database in tree view what code should i write?

Eg: my output should be:

+Tables
+Views
+Procedures
+Triggers and so

so when i click on Tables it should show me all tables present.
Posted
Comments
Sergey Alexandrovich Kryukov 27-Jan-14 15:33pm    
It may or may not be possible to do in a consistent way, because relational model support general object graphs, not just trees.
If you need to show some tree view, use TreeView, or its combination with DataGridView or ListView...
—SA
Charlemagne Gustilo 6-Feb-14 4:25am    
Hi, you can try using the following scripts to read items from the database:

select * from sys.tables
select * from sys.views
select * from sys.procedures
select * from sys.triggers

Then you can try adding nodes from the treeview following the sample in http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview(v=vs.110).aspx

Hope this helps.
archies_gall 14-Feb-14 12:11pm    
Thank you :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900