HighTechTalks DotNet Forums  

Populate TreeView from DATABASE table

Dotnet Framework (WinForms DataBinding) microsoft.public.dotnet.framework.windowsforms.databinding


Discuss Populate TreeView from DATABASE table in the Dotnet Framework (WinForms DataBinding) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
julio1228
 
Posts: n/a

Default Populate TreeView from DATABASE table - 07-10-2008 , 11:42 AM






Hello, I would like some help in order to populate treeview from a database
table the structure of the table is as fallows ID (string), PARENTID(String),
DESCRIPTION (string),
rows sample
'1','0','activo'
'11','1','hello'
'31','3','hello'
VB.net 2008

I've been working arround a code I found on the web, but cant get it to work.
at first run
' Create Parent's NODES on Load
Private Sub FormPlanCashFlow_Load(ByVal sender As Object, ByVal e As System.
EventArgs) Handles Me.Load
Call FormLogin.Carga_Coneccion()
TreeView1.Nodes.Clear()
TreeView1.Nodes.Add(New TreeNode("Catalogo_Contable"))
Dim tNode As New TreeNode
tNode = TreeView1.Nodes(0)
PopulateTreeView(0, tNode)
tNode.Expand()

Call FormLogin.Close_Coneccion()
End Sub
' Recursive function to fill treeview
Private Sub PopulateTreeView(ByVal inParentID As String, ByRef inTreeNode
As TreeNode)
Call FormLogin.Carga_Coneccion()
dsAccountSQL1.Clear()

daAccount1.SelectCommand = New SqlCommand("SELECT id, description,
parent_acct_id FROM accounts WHERE parent_acct_id= '" & inParentID & "'",
FormLogin.ConnSqlServer)
daAccount1.Fill(dsAccountSQL1, "CatContable")
Dim count As Integer
count = dsAccountSQL1.Tables("CatContable").Rows.Count
'drLoadData1.Table.Clear()
Dim ParentTable As DataTable = New DataTable("CatContable")
ParentTable = dsAccountSQL1.Tables("CatContable")

If count > 0 Then
For Each ModuleParameters.drLoadData1 In ParentTable.Rows
Dim parentnode As TreeNode
Dim strLabel As String = ModuleParameters.drLoadData1.Item(0)
& "--" & ModuleParameters.drLoadData1.Item(1)
parentnode = New TreeNode(strLabel)
inTreeNode.Nodes.Add(parentnode)

parentnode.Tag = ModuleParameters.drLoadData1(0)
PopulateTreeView(ModuleParameters.drLoadData1.Item (0),
parentnode)
Next
ElseIf count = 0 Then
PopulateTreeView("0", TreeView1.Nodes(0))
End If

Call FormLogin.Close_Coneccion()
End Sub


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.