Populate treeview

How to setup a access database table to populate treeview

Page 1 of 1

6 Replies - 13938 Views - Last Post: 21 January 2010 - 08:58 AM Rate Topic: -----

#1 CheyNash  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 18-July 08

Populate treeview

Post icon  Posted 18 July 2008 - 01:45 AM

Hey,

as a newby here a first question, I'll try to populate a treeview from a database table, but can't get the table structure right, don't understand how to get my table set for by example a treeview sight of 7 children from the root.
I understand how to populate the treeview at design time, that's no problem, but trough a table ???
Can some one give me a helping hand please

Regarts
CheyNash

Is This A Good Question/Topic? 0
  • +

Replies To: Populate treeview

#2 dineeshd  Icon User is offline

  • member icon

Reputation: 38
  • View blog
  • Posts: 619
  • Joined: 30-June 08

Re: Populate treeview

Posted 18 July 2008 - 01:56 AM

Below thread explained how to populate treeview from Database using C#, same method you can use in VB.

http://www.dreaminco.../snippet922.htm

This post has been edited by dineeshd: 18 July 2008 - 02:23 AM

Was This Post Helpful? 0
  • +
  • -

#3 CheyNash  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 18-July 08

Re: Populate treeview

Posted 18 July 2008 - 02:17 AM

View Postdineeshd, on 18 Jul, 2008 - 01:56 AM, said:

Below thread had explained how to populate treeview from Database using C#, same method you can use in VB.

http://www.dreaminco.../snippet922.htm


I thank You for the very fast replay, I'll look into it, hope I understand all of it

Regarts
Cheynash
Was This Post Helpful? 0
  • +
  • -

#4 CheyNash  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 18-July 08

Re: Populate treeview

Posted 21 July 2008 - 11:30 PM

View Postdineeshd, on 18 Jul, 2008 - 01:56 AM, said:

Below thread explained how to populate treeview from Database using C#, same method you can use in VB.

http://www.dreaminco.../snippet922.htm


dear dineeshd,

I'll have worked my brains out to understand the code in C you send me, but sorry, it's to complicated for me. I love to use all I've got and am proud if some of my code works fine, but I'm a novice and have a lot to learn.
Can you, if it's possible give me an VB6 example, I would be very greatfull.
I'll tryed to send You a messege but that also didn't worked.
CheyNash
Was This Post Helpful? 0
  • +
  • -

#5 dineeshd  Icon User is offline

  • member icon

Reputation: 38
  • View blog
  • Posts: 619
  • Joined: 30-June 08

Re: Populate treeview

Posted 22 July 2008 - 12:35 AM

Right now I don't have any VB6 sample. Let me search more to get one... :rolleyes:
Was This Post Helpful? 0
  • +
  • -

#6 ankush.mukherjee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-January 10

Re: Populate treeview

Posted 21 January 2010 - 03:13 AM

View Postdineeshd, on 21 Jul, 2008 - 11:35 PM, said:

originally posted:
dear dineeshd,
I'll have worked my brains out to understand the code in C you send me, but sorry, it's to complicated for me. I love to use all I've got and am proud if some of my code works fine, but I'm a novice and have a lot to learn.
Can you, if it's possible give me an VB6 example, I would be very greatfull.
I'll tryed to send You a messege but that also didn't worked.
CheyNash

Set nodx = TreeView1.Nodes.Add(, , , "Windows")
nodx.Expanded = True
Set rs = New ADODB.Recordset
	strSQL = "select distinct windows from Master_final"
	rs.Open strSQL, cn
	If Not (rs.EOF And rs.BOF) Then
	rs.MoveFirst
	Do While Not rs.EOF
	windows = rs.Fields(0).Value
   Set nodrs = TreeView1.Nodes.Add(nodx, tvwChild, , windows)
	rs.MoveNext
	Loop
	End If
Set nodx = TreeView1.Nodes.Add(, , , "office")
nodx.Expanded = True
Set rs = New ADODB.Recordset
	strSQL = "select distinct office from Master_final"
	rs.Open strSQL, cn
	If Not (rs.EOF And rs.BOF) Then
	rs.MoveFirst
	Do While Not rs.EOF
	office = rs.Fields(0).Value
   Set nodrs = TreeView1.Nodes.Add(nodx, tvwChild, , office)
	rs.MoveNext
	Loop
	End If


This is the way i did fill my tree view.
Check it out
Happy Programming
Was This Post Helpful? 0
  • +
  • -

#7 vb5prgrmr  Icon User is offline

  • D.I.C Lover

Reputation: 109
  • View blog
  • Posts: 1,016
  • Joined: 21-March 09

Re: Populate treeview

Posted 21 January 2010 - 08:58 AM

Table structure...
tblTreeView
iTVID (autonumber)
iRefID (references iTVID)
vText (text to be shown as the node)

So a root node would be
1, 0, Root1
2, 0, Root2

and then child nodes would be...
3, 1, 1st child node of Root1
4, 3, 1st child node of 1st child node of Root1
5, 3, 1st child node of Root2

Then to populate...
strSQL = "SELECT * FROM tblTreeView WHERE iRefID = 0"
'execute rs, loop through rs to add roots

Rs1.MoveFirst 'now to go back and populate the first level (can also be done when node is expanded

Do While Rs1.EOF = False
strSQL = "SELECT * FROM tblTreeView WHERE iRefID = Rs1.Fields("iTVID").Value
'rs2 execute, loop, add

after that you may want to populate from the node expand event...



Good Luck
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1