Solved

adding a node to the selected node of a treeview

Posted on 2010-11-10
5
891 Views
Last Modified: 2013-12-17
Hi,

I have this:

But i get the errors at line 7:
->The best overloaded method match for 'System.Windows.Forms.TreeNodeCollection.Add(string, string)' has some invalid arguments
->Argument 1: cannot convert from 'System.Windows.Forms.TreeNode' to 'string'      

Who can help me?

P      
string NewText = "";

            if (InputBox.Show("New Folder", "Folder Name", ref NewText, validation) == DialogResult.OK)

            {

                TreeNode n = new TreeNode();

               // MessageBox.Show(NewText);

                TreeNode n2 = tvNotes.SelectedNode;

                n.Nodes.Add(n2, NewText);

            }

Open in new window

0
Comment
Question by:peterkiers
  • 2
  • 2
5 Comments
 
LVL 7

Expert Comment

by:mkobrin
Comment Utility
Try
n.Nodes.Add(n2.ToString(), NewText);
or
n.Nodes.Add(Convert.ToString(n2), NewText);
or
n.Nodes.Add(n2.Text, NewText);
0
 
LVL 7

Assisted Solution

by:mkobrin
mkobrin earned 200 total points
Comment Utility
Or if you want to add the node itself then
n.Nodes.Add(n2);
0
 
LVL 1

Author Comment

by:peterkiers
Comment Utility
I have this now, its error free but it does not work:


            string NewText = "";
            if (InputBox.Show("New Folder", "Folder Name", ref NewText, validation) == DialogResult.OK)
            {
                TreeNode n = new TreeNode();
                TreeNode n2 = tvNotes.SelectedNode;
                n.Nodes.Add(n2.Text, NewText);
            }

Do you know perhaps why?

p.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 300 total points
Comment Utility
You want to add a new node to the selected node. At the moment you're creating a new node (that isn't part of the tree) and adding to it.

You want to be doing something like:
TreeNode n2 = tvNotes.SelectedNode;

n2.Nodes.Add(NewText);

Open in new window

0
 
LVL 1

Author Comment

by:peterkiers
Comment Utility
Oke thanx.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now