0

I'm going to make this as clear as I can, if I leave any details out that would help you help me get it working right, please let me know.

Ok, so what I want to do is:

I have a treeview list, which I want to add Parent Nodes and Child Nodes to, based on ID's.

So, ID's could come in like 32736 and I want it added to the Treeview (Even if it doesn't have any value between 6 - 32736)

Is there anyway possible of doing this? thanks.

3
  • 2
    Is this a WinForms TreeView, or an Asp.NET TreeView? Commented Mar 29, 2011 at 19:05
  • 1
    A treeview implies a hierarchy and your question needs to better explain what constitutes a parent node vs. a child node. Perhaps you can provide a few examples of the input data and where on your treeview you'd expect each to appear. Commented Mar 29, 2011 at 19:05
  • "I have a treeview list" - there is no such thing. Also tag WinForms, WPF or WebForms Commented Mar 29, 2011 at 19:23

3 Answers 3

1

You can add nodes with any key (id) you want if you're adding them manually.

See here: http://msdn.microsoft.com/en-us/library/57aa8e09.aspx for WinForms. It's pretty much the same code for the Asp.Net TreeView.

code for defining a new Asp.Net Treenode here: http://msdn.microsoft.com/en-us/library/12bxet86.aspx

Then just add it to the collection

TreeNode myNewNode = new TreeNode("SomeTextToDisplay", "SomeId");
myTreeView.Nodes.Add(myNewNode);
Sign up to request clarification or add additional context in comments.

Comments

0

Check out http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.nodes.aspx When adding the nodes make sure to do it from the primary UI thread to avoid a cross thread exception or use the TreeView.BeginInvoke() method to have the action performed on the correct thread.

TreeViewToModify.BeginInvoke(delegate() => TreeViewToModify.Nodes.Add(new TreeViewNode(id)));

Keep in mind this is not taking into account adding to specific parent/child nodes but the logic is the same.

Comments

0
TreeView1.Nodes.Clear();
TreeNode root = new TreeNode("Base");
TreeView1.Nodes.Add(root);
TreeNode sub = new TreeNode("32736");
root.Nodes.Add(sub);

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.