473,324 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

make a treeview from database

QT
Dear Sirs,

I have a database table which has 4 column such as

Document Name
Subpart
Title

I want to make a treeview like this

+ Document Name
+Subpart
-Tittle

I try several way but I can not add child nodes after adding document names.
Where can I find good explanation?

Best Regrads
Nov 20 '05 #1
6 3522
Hi,

Add a new node for each record. Here is an example.

Imports System.Data.SqlClient

Public Class Form1

Inherits System.Windows.Forms.Form

Dim ds As New DataSet

Dim dvCustomers As DataView

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim conn As SqlConnection

Dim daCustomers As SqlDataAdapter

Dim daOrders As SqlDataAdapter

Dim strConn As String

strConn = "Data Source = " + SystemInformation.ComputerName

strConn += "\VSdotNet; Initial Catalog = NorthWind;"

strConn += "Integrated Security = SSPI;"

conn = New SqlConnection(strConn)

daCustomers = New SqlDataAdapter("Select * from Employees order by LastName,
FirstName", conn)

daCustomers.Fill(ds, "Clients")

dvCustomers = New DataView(ds.Tables("Clients"))

AddNodes()

End Sub

Private Sub AddNodes()

Dim drCustomer As DataRowView

Dim root As System.Windows.Forms.TreeNode

Dim strName As String

With trvNorthWind

..BeginUpdate()

..Nodes.Clear()

For Each drCustomer In dvCustomers

strName = drCustomer.Item("FirstName") & " " & drCustomer.Item("LastName")

Dim n As TreeNode

n = New TreeNode(strName)

Dim snCountry As TreeNode

Dim snCity As TreeNode

snCity = New TreeNode(drCustomer.Item("City"))

snCountry = New TreeNode(drCustomer.Item("Country"))

snCountry.Nodes.Add(snCity)

n.Nodes.Add(snCountry)

trvNorthWind.Nodes.Add(n)

Next drCustomer

..EndUpdate()

End With

End Sub

End Class

Ken
---------------------------
"QT" <we*****@yahoo.com> wrote in message
news:uZ*************@tk2msftngp13.phx.gbl...
Dear Sirs,

I have a database table which has 4 column such as

Document Name
Subpart
Title

I want to make a treeview like this

+ Document Name
+Subpart
-Tittle

I try several way but I can not add child nodes after adding document
names.
Where can I find good explanation?

Best Regrads

Nov 20 '05 #2
"QT" <we*****@yahoo.com> schrieb
Dear Sirs,

I have a database table which has 4 column such as

Document Name
Subpart
Title

I want to make a treeview like this

+ Document Name
+Subpart
-Tittle

I try several way but I can not add child nodes after adding document
names. Where can I find good explanation?

Best Regrads


Write a recursive procdedure. Pass a System.Windows.Forms.TreeNodeCollection
collection to the sub. Calling the sub the first time, pass treeview1.nodes.
Within the procedure, add a node and call the procedure passing the node's
Nodes collection.

http://msdn.microsoft.com/library/en...Procedures.asp
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
* "QT" <we*****@yahoo.com> scripsit:
I have a database table which has 4 column such as

Document Name
Subpart
Title

I want to make a treeview like this

+ Document Name
+Subpart
-Tittle

I try several way but I can not add child nodes after adding document names.
Where can I find good explanation?


Loop though the rows and add the items:

\\\
Dim tnDocument As TreeNode = Me.TreeView1.Nodes.Add(...)
Dim tnSubPart As TreeNode = tnDocument.Nodes.Add(...)
tnSubPart.Nodes.Add(...)
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
"One Handed Man [ OHM# ]" <OneHandedMan{at}BTInternet{dot}com> schrieb.
Hey Armin,
You really do know your stuff dont you. I wonder how
you are not an MVP already ?


I tried to write you an email. {at} replaced by "@" and {dot} replaced by
".". It came back. Still not the right address?
--
Armin

Nov 20 '05 #5

Sorry, I had to delete this because of huge spam mail

Try

O_H_M(at)BTINTERNET.COM

Armin Zingler wrote:
"One Handed Man [ OHM# ]" <OneHandedMan{at}BTInternet{dot}com>
schrieb.
Hey Armin,
You really do know your stuff dont you. I wonder
how you are not an MVP already ?


I tried to write you an email. {at} replaced by "@" and {dot}
replaced by ".". It came back. Still not the right address?


Regards - OHM# OneHandedMan{at}BTInternet{dot}com
Nov 20 '05 #6
QT
Dear Armin,

I try to understand your idea and I read link. But I could not compose some
scripts with your idea. May be I have some problem when adding node into
treeview.

I am using following scripts to add node

Dim Node As TreeNode

Node = TreeView1.Nodes.Add("level1")

Node.Nodes.Add("level2")

As far as I know, I should dim level 1 Node and to add childs into it. But I
can not dim document names which are coming from database. So within
recursive procedure, I can not use above script.

Am I using wrong method to add nodes?


"Armin Zingler" <az*******@freenet.de> wrote in message
news:er**************@TK2MSFTNGP10.phx.gbl...
"QT" <we*****@yahoo.com> schrieb
Dear Sirs,

I have a database table which has 4 column such as

Document Name
Subpart
Title

I want to make a treeview like this

+ Document Name
+Subpart
-Tittle

I try several way but I can not add child nodes after adding document
names. Where can I find good explanation?

Best Regrads
Write a recursive procdedure. Pass a

System.Windows.Forms.TreeNodeCollection collection to the sub. Calling the sub the first time, pass treeview1.nodes. Within the procedure, add a node and call the procedure passing the node's
Nodes collection.

http://msdn.microsoft.com/library/en...ngRecursivePro
cedures.asp

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
by: lauren quantrell | last post by:
So many postings on not to use the treeview control, but nothing recently. Is it safe to swim there yet with Access 2000-Access 2003?
3
by: Soul | last post by:
Hi, I am learning C# at the moment. I am trying to develop a simple program that will get data from a MS Access database into a dataSet. The result of dataSet should be something like: Year ...
6
by: Jan Krouwer | last post by:
I have a treeview which is populated from a relational database. In order to copy part of the tree, I need to add to the database the relationship of the part of the tree to be copied but with new...
3
by: Jan Wrage | last post by:
Hi! I would like to implement a treeview in my existing application. It should show my entire Active-Directory structure, i.e. all Groups, Containers and OUs. Could somebody help me with...
7
by: vsiat | last post by:
I am trying to create a treeview out of a database table with the typical structure ID, NAME, PARENTID, TYPE, EXTRA_INFO, where is linked to the . What I want to achieve is create a tree made...
1
by: cjinsocal581 | last post by:
Hi all, I am struggling with the following: Environement: VB.NET 2005 TreeView Control SQL Database I need to be able to save a TreeView's nodes into a SQL database and then be able to call...
2
by: makennedy | last post by:
Hi Experts, Please help, I am a newbie to ASP.NET 2.0 may be I am doing something wrong or there may be a bug somewhere. Basically I have a TreeView Control which I have created...
0
by: Falcula | last post by:
Hello, I have a treeview that i fill from a database, when i update nodename in database the treeview dont update. Its works when iam not useing enableviewstate="true" but then i loosing the...
5
by: Max2006 | last post by:
Hi, I have a TreeView and this is my node style: <asp:TreeNodeStyle ForeColor = "#000000" Font-Size="9px" Font-Bold="false" Width="100px" NodeSpacing="3px" /> The problem is the expand...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.