Treeview problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MaPet

    #1

    Treeview problem

    He. I'm trying to create a treeview that will show data from access database
    in hierarchical way. Database structure is: ID, FirstName, LastName,
    IDBoss - IDBoss is referenced to ID. Treeview should look like this:

    -employee1

    ---employee2

    ---employee3

    ------employee4

    ---employee5

    ---employee6

    ------employee7

    ---------employee8

    ------employee9



    Can someone please send here some code (please in vb.net 2005) that will do
    that work, or give me a hint. So far I create function that populate
    treeview but only 3 levels.

    Here is my code:



    (Sorry on my english)

    ----


    Private Sub FillTree()

    Dim conn As New OleDb.OleDbConn ection("Provide r=Microsoft.Jet .OLEDB.4.0;Data
    Source=|DataDir ectory|\baza.md b")

    Dim rootAdapter As New OleDb.OleDbData Adapter("SELECT * FROM zaposlenici
    WHERE ID = 1", conn)

    Dim childAdapter As New OleDb.OleDbData Adapter("SELECT * FROM zaposlenici
    WHERE ID <1", conn)

    Dim treeDataSet As New DataSet()

    treeDataSet.Enf orceConstraints = False

    rootAdapter.Fil l(treeDataSet, "Parents")

    childAdapter.Fi ll(treeDataSet, "Children")

    treeDataSet.Rel ations.Add("rel acija",
    treeDataSet.Tab les("Parents"). Columns("ID"), _

    treeDataSet.Tab les("Children") .Columns("IDBos s"))

    treeDataSet.Rel ations.Add("rel acija2", _

    treeDataSet.Tab les("Children") .Columns("ID"), _

    treeDataSet.Tab les("Children") .Columns("IDBos s"))

    TreeView1.Nodes .Clear()

    Dim parent As DataRow

    For Each parent In treeDataSet.Tab les("Parents"). Rows

    Dim parentNode As New TreeNode(parent ("LastName").To String() & " " &
    parent("FirstNa me").ToString() )

    Dim child As DataRow

    For Each child In parent.GetChild Rows("relacija" )

    Dim folderNode As New TreeNode(child( "LastName").ToS tring() & " " &
    child("FirstNam e").ToString ())

    Dim item As DataRow

    For Each item In child.GetChildR ows("relacija2" )

    folderNode.Node s.Add(New TreeNode(item(" LastName").ToSt ring() & " " &
    item("FirstName ").ToString ()))

    Next item

    parentNode.Node s.Add(folderNod e)

    Next child

    TreeView1.Nodes .Add(parentNode )

    Next parent

    TreeView1.Expan dAll()

    End Sub


  • Steven Nagy

    #2
    Re: Treeview problem

    I would solve this by:

    Filling a dataset with all employees.
    Using RECURSION I would add an employee, and then iterate through the
    dataset to find any one below him.

    Rinse, lather, and repeat.

    Comment

    • MaPet

      #3
      Re: Treeview problem


      "Steven Nagy" <learndotnet@ho tmail.comwrote in message
      news:1152762448 .574278.33900@p 79g2000cwp.goog legroups.com...
      >I would solve this by:
      >
      Filling a dataset with all employees.
      Using RECURSION I would add an employee, and then iterate through the
      dataset to find any one below him.
      >
      Rinse, lather, and repeat.
      >
      can you write some example code, please.


      Comment

      Working...