1

I have a treeview on my form and in that treeview there are screen resolutions categorized to their type (categories: 16:9, 16:10, 4:3 etc...) and there are one last node which is labelled "Custom".

I would like to enable users to add their own resolutions by typing numbers in textboxes and clicking a button.

I have successfully written the code to add nodes but everytime i add a custom resolution, it creates a new root node called "Custom". How can I make them go under one "Custom" node?

Here's my code:

Form1.TreeView1.Nodes.Add("Custom").Nodes.Add(TextBox1.Text + "x" + TextBox2.Text)
Dawood Ahmed
  • 1,734
  • 4
  • 23
  • 36

2 Answers2

1

Remove first .Add word in your code:

Form1.TreeView1.Nodes("Custom").Nodes.Add(TextBox1.Text + "x" + TextBox2.Text)

or make a more safely code

Dim customnode as TreeNode = Form1.TreeView1.Nodes("Custom")
If customnode IsNot Nothing Then
    customnode.Nodes.Add(TextBox1.Text + "x" + TextBox2.Text)
End If
Fabio
  • 31,528
  • 4
  • 33
  • 72
  • Apparently the the name of that node wasn't "Custom" but "Node22". So when I renamed "Custom" in your code to "Node22", it worked great! –  Jan 09 '14 at 02:08
0

Form1.TreeView1.Nodes.Find("Custom", True).First.Nodes.Add(TextBox1.Text + ":" + TextBox2.Text)

The Find is used to recursively search for the Node with the key "Custom".

Gandy
  • 11
  • 2