Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

adding a node to the selected node of a treeview

Posted on 2010-11-10
5
Medium Priority
?
913 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 7

Expert Comment

by:mkobrin
ID: 34099996
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 800 total points
ID: 34100007
Or if you want to add the node itself then
n.Nodes.Add(n2);
0
 
LVL 1

Author Comment

by:peterkiers
ID: 34100030
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 1200 total points
ID: 34100047
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
ID: 34100063
Oke thanx.
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

705 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