Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refresh treeview but open expanded values

Status
Not open for further replies.

aspvbnetnerd

Programmer
May 16, 2006
278
SE
I have a treeview that I build the database when my application is loaded.
If the user adds a new customer then I have to Call refTreeview to show them the new added customer.
If I call refTreeview I want to be able to expand the menu that the user has expanded.

My Code
Code:
[COLOR=blue]Public Sub refTrevieew()[/color]
[code][COLOR=green]' Builds the menu for the treeview
[/color]Dim NodeParent [COLOR=blue]As[/color] TreeNode
Dim NodeChild [COLOR=blue]As[/color] TreeNode
Dim NodeChildU [COLOR=blue]As[/color] TreeNode

mDataAdapter = [COLOR=#FF00FF]New[/color] DataAdapter
[COLOR=blue]Call[/color] mDataAdapter.init(g_ConnectionString)

[COLOR=green]' TreeView
[/color][COLOR=blue]With[/color] TrViewCustomer
    [COLOR=green]' Suppress repainting the TreeView until all the objects have been created.
[/color]    .BeginUpdate()
    .Nodes.Clear()                  [COLOR=green]' Clear all nodes
[/color]
    [COLOR=green]'Mainmenu
[/color]    NodeParent = .Nodes.Add(FormLogIn.htbLang.Item(10001).ToString)     [COLOR=green]'Customer
[/color]
    [COLOR=green]'2007-06-01 : Call Sp (usp_getAllCustomer)
[/color]    mSqlDr = mDataAdapter.getAllCustomer()
    [COLOR=blue]While[/color] mSqlDr.Read()

        NodeChild = NodeParent.Nodes.Add(mSqlDr.Item("CustomerID").ToString, mSqlDr.Item("CustomerName").ToString)
        NodeChild.Tag = mSqlDr.Item("CustomerID")
        [COLOR=green]'Get all assignment from a customer
[/color]        mSqlDrCustomerAssignment = mDataAdapter.getCustomerAssignment(CType(mSqlDr.Item("CustomerID"), [COLOR=blue]Integer[/color]))
        [COLOR=blue]While[/color] mSqlDrCustomerAssignment.Read()
            NodeChildU = NodeChild.Nodes.Add(mSqlDrCustomerAssignment.Item(2).ToString.PadRight(6, CType(" ", [COLOR=blue]Char[/color])) + mSqlDrCustomerAssignment.Item(4).ToString.PadLeft(2, CType("0", [COLOR=blue]Char[/color])))
            .Tag = mSqlDrCustomerAssignment.Item("AssignmentID")
            NodeChildU.Tag = .Tag
        [COLOR=blue]End[/color] [COLOR=blue]While[/color]

        [COLOR=green]'Cleaning up
[/color]        mSqlDrCustomerAssignment.Close()
        mSqlDrCustomerAssignment = Nothing

    [COLOR=blue]End[/color] [COLOR=blue]While[/color]

    .EndUpdate()                    [COLOR=green]' Begin repainting the TreeView.
[/color]    .[COLOR=blue]Sort[/color]()                         [COLOR=green]' Sorting all the nodes
[/color]
[COLOR=blue]End[/color] [COLOR=blue]With[/color]

mSqlDr.Close()
mSqlDr = Nothing
mDataAdapter.dispose()
mDataAdapter = Nothing

Code:
[COLOR=blue]End Sub[/color]

Any help is appriciated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top