How to populate a treeview from a dataset

X

xmail123

I am very new to C#. I need to create a Windows form that will read a
SQL table and populate a treeview. I can connect to the DB, create
the dataadapter, populate a data set. The problem is how to use the
dataset to populate a treeview.

I have looked at a few examples but none use a dataset, or the
data structure was different and I could not modify to work with my
data or the examples were more than I needed and too complex for a
beginner. Can some one suggest a URL, book or show me an example of
code that simply takes the data as shown and populates a treeview.

I would really appreciate the help.

Thank you.


I have a SQL Server 2005 table containing this data shown below.

Child Parent depth Hierachy
1 NULL 0 01
2 1 1 01.02
5 2 2 01.02.05
6 2 2 01.02.06
3 1 1 01.03
7 3 2 01.03.07
11 7 3 01.03.07.11
14 11 4 01.03.07.11.14
12 7 3 01.03.07.12
13 7 3 01.03.07.13
8 3 2 01.03.08
9 3 2 01.03.09
4 1 1 01.04
10 4 2 01.04.10
15 NULL 0 15
15 15 1 15.15
16 15 1 15.16
18 16 2 15.16.18
17 15 1 15.17
 
X

xmail123

WOW That does everything. Definitely not a new bee piece of code. Is
there a chunk of it that simply populates a treeview from a recursive
table? Or could you point me to a URL with a simple basic example?

Thanks


TreeView, DataSet, DataBind, Drag n Drop

http://www.eggheadcafe.com/articles/treeview_databinding.asp

--
Robbe Morris [Microsoft MVP - Visual C#]
.NET PropertyGrid Control - ListBox, ComboBox, and Custom Classes
http://www.eggheadcafe.com/tutorial...af-5cd3abe27a75/net-propertygrid-control.aspx




I am very new to C#. I need to create a Windows form that will read a
SQL table and populate a treeview. I can connect to the DB, create
the dataadapter, populate a data set. The problem is how to use the
dataset to populate a treeview.

I have looked at a few examples but none use a dataset, or the
data structure was different and I could not modify to work with my
data or the examples were more than I needed and too complex for a
beginner. Can some one suggest a URL, book or show me an example of
code that simply takes the data as shown and populates a treeview.

I would really appreciate the help.

Thank you.


I have a SQL Server 2005 table containing this data shown below.

Child Parent depth Hierachy
1 NULL 0 01
2 1 1 01.02
5 2 2 01.02.05
6 2 2 01.02.06
3 1 1 01.03
7 3 2 01.03.07
11 7 3 01.03.07.11
14 11 4 01.03.07.11.14
12 7 3 01.03.07.12
13 7 3 01.03.07.13
8 3 2 01.03.08
9 3 2 01.03.09
4 1 1 01.04
10 4 2 01.04.10
15 NULL 0 15
15 15 1 15.15
16 15 1 15.16
18 16 2 15.16.18
17 15 1 15.17
 
R

Robbe Morris - [MVP] C#

You could always just download the sample and step through
it yourself...

The primary methods you are after is:

LoadFromDataSet
AddNodeFromDataRow

--
Robbe Morris [Microsoft MVP - Visual C#]
..NET PropertyGrid Control - ListBox, ComboBox, and Custom Classes
http://www.eggheadcafe.com/tutorial...af-5cd3abe27a75/net-propertygrid-control.aspx




WOW That does everything. Definitely not a new bee piece of code. Is
there a chunk of it that simply populates a treeview from a recursive
table? Or could you point me to a URL with a simple basic example?

Thanks


TreeView, DataSet, DataBind, Drag n Drop

http://www.eggheadcafe.com/articles/treeview_databinding.asp

--
Robbe Morris [Microsoft MVP - Visual C#]
.NET PropertyGrid Control - ListBox, ComboBox, and Custom Classes
http://www.eggheadcafe.com/tutorial...af-5cd3abe27a75/net-propertygrid-control.aspx




I am very new to C#. I need to create a Windows form that will read a
SQL table and populate a treeview. I can connect to the DB, create
the dataadapter, populate a data set. The problem is how to use the
dataset to populate a treeview.

I have looked at a few examples but none use a dataset, or the
data structure was different and I could not modify to work with my
data or the examples were more than I needed and too complex for a
beginner. Can some one suggest a URL, book or show me an example of
code that simply takes the data as shown and populates a treeview.

I would really appreciate the help.

Thank you.


I have a SQL Server 2005 table containing this data shown below.

Child Parent depth Hierachy
1 NULL 0 01
2 1 1 01.02
5 2 2 01.02.05
6 2 2 01.02.06
3 1 1 01.03
7 3 2 01.03.07
11 7 3 01.03.07.11
14 11 4 01.03.07.11.14
12 7 3 01.03.07.12
13 7 3 01.03.07.13
8 3 2 01.03.08
9 3 2 01.03.09
4 1 1 01.04
10 4 2 01.04.10
15 NULL 0 15
15 15 1 15.15
16 15 1 15.16
18 16 2 15.16.18
17 15 1 15.17
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top