Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb_dotnet thread: Treeview Populating in vbnet


Message #1 by "Gabriel Brienza" <vbnetuk@y...> on Mon, 7 Jan 2002 11:11:49
OK.  This code snipet is for discussion only.  It is part of a larger
copywritten project prepared by Phase1 Systems, Inc. of Sonoita, Arizona.

' DrawMenus() creates the top level node attached to the control itself
' tvstuff is the TreeView control
' "TOOLBAR" is the root of the entire tree
Protected Sub DrawMenus()

Dim oRoot As TreeNode

tvStuff.Visible = True

tvStuff.BeginUpdate()  ' holds off updating the tree painting until all
edits are done

tvStuff.Nodes.Clear()

oRoot = tvStuff.Nodes.Add("TOOLBAR")

tvStuff.SelectedNode = oRoot

MenuNode("00", "TOOLBAR", oRoot) ' start at the top node

tvStuff.EndUpdate()    ' now draw the tree

End Sub

' Sub MenuNode builds all the tree nodes below those attached to the control

Protected Sub MenuNode(ByVal strLevel As String, _

ByVal strParent As String, _

ByVal oParent As TreeNode)

Dim iRow As Integer

Dim aDataRowView As DataRowView

Dim aDataView As DataView

Dim strChild As String

Dim strLevelID() As String

Dim strChildren As String

Dim strChildrenFound() As String

Dim nCount As Integer

Dim oChild As TreeNode

Dim strTitle As String

' Find all child nodes with the current parent

aDataView = New DataView(aDataset.Tables("Menu"))

aDataView.RowFilter = "[Parent] = '" & strParent & "'"

aDataView.Sort = "[seqno],[Child]"

'tvStuff.Visible = True



If aDataView.Count > 0 Then

' collect all nodes with same parent

    For iRow = 0 To aDataView.Count - 1

        nCount = nCount + 1

        aDataRowView = aDataView.Item(iRow)

        strChild = aDataRowView.Item("Child").ToString

        ReDim Preserve strChildrenFound(nCount)

        ReDim Preserve strLevelID(nCount)

        strChildrenFound(nCount - 1) = strChild

        strChildren = strChildren & strChild & ", "

        Debug.WriteLine(strChild)

        strLevelID(iRow) = strLevel & Microsoft.VisualBasic.Right("00" &
iRow, 2)

'' make a main/sub menu item here!!!!!

    Next

    sbStat.Text = "Check item to attach to a new parent, then select (left
click) new parent then right click to move children."

'' MsgBox("Children Found: " & strChildren & " for parent: " & strParent)

' process children next

    For iRow = 0 To nCount - 1

' process TreeView Menu build next

        oChild = oParent.Nodes.Add(strChildrenFound(iRow))

'''' process child menu nodes here

        MenuNode(strLevelID(iRow), strChildrenFound(iRow), oChild)

    Next

    oChild = Nothing

End If

End Sub

----- Original Message -----
From: "Gabriel Brienza" <vbnetuk@y...>
To: "pro_VB_dotnet" <pro_vb_dotnet@p...>
Sent: Tuesday, January 08, 2002 12:37 AM
Subject: [pro_vb_dotnet] Re: Treeview Populating in vbnet


> >
> >  Hi Richard
>
> Thank you for your reply.I will go and see that book that you mentioned.
>
> I Have read your email and I will try to implement what I used to do in
> vb6 to vbnet.
> I suppose I could use the tag property instead of the key.
>
> I do not want to be a pain but to have a real example would make things
> much clear in my head.
>
> Do you  happen to have  an example about the populating the treeview
> something that you done.
> Is this too much to ask? (using northwind db)
>
> Sorry but here in London there is a recession and unless I can learn and
> offer (vbnet)something more i will be out of job.
>
> Thanks a lot for your reply
> Gabriel
>
$subst('Email.Unsub').


  Return to Index