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)

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

1 Comment

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!
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".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.