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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding treeview node at runtime

Status
Not open for further replies.

Bluejay07

Programmer
Mar 9, 2007
780
CA
Hello,

I have a treeview with several root nodes added at design time. I am trying to add another node at runtime, however, the node does not appear.

I only want this node to be available if the user is an administrator.

Code:
If g_bolAdmin Then
   tvwconfig.Nodes.Add("UserInfo", "User Information")
   'tvwconfig.Nodes("UserInfo").EnsureVisible()
End If

Could anyone help me as too why and how my new node does not appear?

Thanks.
 
It looks fine to me. Are you sure you're getting a true for g_bolAdmin?
 
Hi RiverGuy,

While I was testing, I had the if statements commented out so that the code would always execute. (I even placed breakpoints just to make sure.)

I'll keep trying.
 
I think there is something wrong.

Before the above line is executed, by testing in the immediate window with tvwconfig.Nodes.Count I get 0. After the line is executed I get 1.

So it appears that the code is (somewhat) working, however, it doesn't seem to read the existing nodes. After the code is run, if I click on an existing node, they all display the proper information.

It seems like the new node I am trying to add is not being accepted into the current collection of nodes, but it want to start a new collection of its own.

Would anyone have more information that could help me sort this out?

Thanks.
 
Well I still can't get it to work, so I wanted to try another approach but that isn't working either.

Since adding a new node to existing nodes isn't working and you can't set an individual node to invisible, I thought I would try to build the nodes during runtime. I deleted the node collection in design mode and tried the following code:

Code:
tvwconfig.Nodes.Clear()
tvwconfig.Nodes.Add("Connection", "Connection")
tvwconfig.Nodes.Add("Options", "Options").EnsureVisible()
tvwconfig.Nodes.Add("Security", "Security").EnsureVisible()
tvwconfig.Nodes.Add("UserInfo", "User Information").EnsureVisible()

At runtime, the treeview remains empty.

Essentially, all I want is not to display a certain node if the user doesn't have the appropriate permissions.

Can anymore provide some insight?

Thanks.
 
The two methods I have for adding a treenode would be like this:

Code:
tvwconfig.Nodes.Add(New TreeNode("Connection"))

or

Code:
Dim tn as TreeNode = tvwconfig.Nodes.Add("Connection")
 
After receiving the post from TheVampire, I decided to try a few things.

I determined that the code for TheVampire and my original code does work. The problem is that I had
Code:
Dim tvwConfig as New Treeview
declared. Once commented out, everything worked.

Thanks for the responses.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top