Treeview populate from database

M

Marina

Hello!

I have a database with some customers. Each one of them has 3 other customers under him etc. (something like an MLM system). Now, I want to create a treeview with this. Eg.

C1
C11
C111
C1111
C1112
C1113
C112
C1121
C113
C12
C13


First of all, each of the customers may have max 3 people under him. So my thoughts were to set as the parent node each customer and see if he has others under him and then add them to his tree. My problem is how to set as parent a previously added node? Itried to do this with k=k+1 but it doesn't work. To be more specific let me give u some code i wrote. Any help would be appreciated!
genSQL = "SELECT * FROM Customers order by Upline,Line"
genrs.Open(genSQL, sindesi, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)

Dim cnode As TreeNode
genrs.MoveFirst()

TV1.Nodes.Add(genrs.Fields!FirstName.Value & " " & genrs.Fields!FirstName.Value)

k = 0

Do Until genrs.EOF

vlax = genrs.Fields!Upline.Value & genrs.Fields!Line.Value

geoSQL = "SELECT * FROM Customers WHERE Upline=" & vlax & " and Referrer<>0 order by Upline,Line"

geors.Open(geoSQL, sindesi, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)

cnode = TV1.Nodes.Item(k)

For i = 1 To 3

If Not geors.EOF Then cnode.Nodes.Add(geors.Fields!FirstName.Value & " " & geors.Fields!FirstName.Value)
geors.MoveNext()

Next

k = k + 1

geors.Close()
genrs.MoveNext()

Loop
 
C

Cor Ligthert

Marina,

A treeview is exactly as a chrismass tree.

You can put (add) someting to a node.

The same as in a christmass tree you cannot say that a bell is now a node.

However you can take it out again in a treeview and add it again as a node.
I think that that will be your solution to go.

Anoterh question, there is a regular too these newsgoups who uses the name
Marina.

So it can be confusing when there are two Marina's, will you maybe be so
kind to set something behind your name next time by instance "L"

Thanks in advance

I hope this answer by the way helps so far?

Cor

"Marina" (e-mail address removed)
Hello!

I have a database with some customers. Each one of them has 3 other
customers under him etc. (something like an MLM system). Now, I want to
create a treeview with this. Eg.

C1
C11
C111
C1111
C1112
C1113
C112
C1121
C113
C12
C13


First of all, each of the customers may have max 3 people under him. So my
thoughts were to set as the parent node each customer and see if he has
others under him and then add them to his tree. My problem is how to set as
parent a previously added node? Itried to do this with k=k+1 but it doesn't
work. To be more specific let me give u some code i wrote. Any help would be
appreciated!
genSQL = "SELECT * FROM Customers order by Upline,Line"
genrs.Open(genSQL, sindesi, ADODB.CursorTypeEnum.adOpenDynamic,
ADODB.LockTypeEnum.adLockOptimistic)
Dim cnode As TreeNode
genrs.MoveFirst()
TV1.Nodes.Add(genrs.Fields!FirstName.Value & " " &
genrs.Fields!FirstName.Value)
k = 0
Do Until genrs.EOF
vlax = genrs.Fields!Upline.Value & genrs.Fields!Line.Value
geoSQL = "SELECT * FROM Customers WHERE Upline=" & vlax & " and Referrer<>0
order by Upline,Line"
geors.Open(geoSQL, sindesi, ADODB.CursorTypeEnum.adOpenDynamic,
ADODB.LockTypeEnum.adLockOptimistic)
cnode = TV1.Nodes.Item(k)
For i = 1 To 3
If Not geors.EOF Then cnode.Nodes.Add(geors.Fields!FirstName.Value & " " &
geors.Fields!FirstName.Value)
geors.MoveNext()
Next
k = k + 1
geors.Close()
genrs.MoveNext()
Loop
 
N

Nemertes

Thanks for your info. Actually this thing is going to be a christmas gift
for one of my customers.

What I'm trying to do is to set the new added node as parent node. But let's
make it simpler. How one can populate a treeview with many different levels?

PS. Nemertes is better i think!
 
C

Cor Ligthert

Marina,

Nemertes I never saw what does it mean ? :)

Does this sample I once made help?

\\\Needs only a treeview on a form
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim l As Integer() = {0, 0, 1, 0, 1, 5}
Dim t As New TreeNode("Root")
TreeView1.Nodes.Add(t)
For i As Integer = 1 To 5
Dim tn As New TreeNode
tn = t.Nodes.Add("Root\Node" & i.ToString & "\")
Dim sn As New TreeNode
For j As Integer = 1 To l(i)
sn = tn.Nodes.Add("Root\Node" & i.ToString & "\SubNode\" & _
i.ToString & j.ToString)
Dim sn2 As New TreeNode
For h As Integer = 1 To l(6 - j)
sn2 = sn.Nodes.Add("Root\Node" & i.ToString &
"\SubNode\" & _
i.ToString & j.ToString & "\" _
& "SubNode" & i.ToString & j.ToString & h.ToString)
Next
Next
Next
TreeView1.ExpandAll()
End Sub
///
I hope this helps?

Cor
 
K

Ken Tucker [MVP]

Hi,

Maybe this will help.
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q320755


Ken
-------------------
Hello!

I have a database with some customers. Each one of them has 3 other
customers under him etc. (something like an MLM system). Now, I want to
create a treeview with this. Eg.

C1
C11
C111
C1111
C1112
C1113
C112
C1121
C113
C12
C13


First of all, each of the customers may have max 3 people under him. So my
thoughts were to set as the parent node each customer and see if he has
others under him and then add them to his tree. My problem is how to set as
parent a previously added node? Itried to do this with k=k+1 but it doesn't
work. To be more specific let me give u some code i wrote. Any help would be
appreciated!
genSQL = "SELECT * FROM Customers order by Upline,Line"
genrs.Open(genSQL, sindesi, ADODB.CursorTypeEnum.adOpenDynamic,
ADODB.LockTypeEnum.adLockOptimistic)
Dim cnode As TreeNode
genrs.MoveFirst()
TV1.Nodes.Add(genrs.Fields!FirstName.Value & " " &
genrs.Fields!FirstName.Value)
k = 0
Do Until genrs.EOF
vlax = genrs.Fields!Upline.Value & genrs.Fields!Line.Value
geoSQL = "SELECT * FROM Customers WHERE Upline=" & vlax & " and Referrer<>0
order by Upline,Line"
geors.Open(geoSQL, sindesi, ADODB.CursorTypeEnum.adOpenDynamic,
ADODB.LockTypeEnum.adLockOptimistic)
cnode = TV1.Nodes.Item(k)
For i = 1 To 3
If Not geors.EOF Then cnode.Nodes.Add(geors.Fields!FirstName.Value & " " &
geors.Fields!FirstName.Value)
geors.MoveNext()
Next
k = k + 1
geors.Close()
genrs.MoveNext()
Loop
 
C

Cor Ligthert

Ken,

Used is AdoDB, it does not matter, however it was the reason I was avoiding
this kind of sample.

:)

(The OP knows now that there is a difference therefore more the message)

Cor
 
N

Nemertes

Thanks for your answers. The thing I wrote and got only to Cor was :

Thanks a lot!

Even my problem is not solved, I got a perfect idea of how to add child
nodes. So the next thing is how to pre-determine the levels my tree will
have. I'll find a way don't worry!

Btw, Nemertes is a greek godess, daughter of the god of the sea Nireus,
considered to be the wissest of the sisters and unerritable. This is the
greek version of my latin name (Marina) :)
-------------------------

Now, the topic Ken send me leads me also to the same path. That the is no way of make a completely dynamically tree. So I will only allow his to see the first 10 levels with 10 for... next or 10 for each . In the prog (i do the same thing with crystal reports) only the first person has the right to see more than 10 levels, but since this is not applicable, I would limit it to just 10. This is a gift after all!

Thanks a lot all of you!

Marina




Hello!

I have a database with some customers. Each one of them has 3 other customers under him etc. (something like an MLM system). Now, I want to create a treeview with this. Eg.

C1
C11
C111
C1111
C1112
C1113
C112
C1121
C113
C12
C13


First of all, each of the customers may have max 3 people under him. So my thoughts were to set as the parent node each customer and see if he has others under him and then add them to his tree. My problem is how to set as parent a previously added node? Itried to do this with k=k+1 but it doesn't work. To be more specific let me give u some code i wrote. Any help would be appreciated!
genSQL = "SELECT * FROM Customers order by Upline,Line"
genrs.Open(genSQL, sindesi, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)

Dim cnode As TreeNode
genrs.MoveFirst()

TV1.Nodes.Add(genrs.Fields!FirstName.Value & " " & genrs.Fields!FirstName.Value)

k = 0

Do Until genrs.EOF

vlax = genrs.Fields!Upline.Value & genrs.Fields!Line.Value

geoSQL = "SELECT * FROM Customers WHERE Upline=" & vlax & " and Referrer<>0 order by Upline,Line"

geors.Open(geoSQL, sindesi, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)

cnode = TV1.Nodes.Item(k)

For i = 1 To 3

If Not geors.EOF Then cnode.Nodes.Add(geors.Fields!FirstName.Value & " " & geors.Fields!FirstName.Value)
geors.MoveNext()

Next

k = k + 1

geors.Close()
genrs.MoveNext()

Loop
 
Top