Solved

adding a node to the selected node of a treeview

Posted on 2010-11-10
5
905 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 200 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 300 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Inserting LocalDB Table to SQL Server C# 3 51
asp.net repeater 2 38
GET INFO ABOUT WHAT THE PRINTER IS DOING ? 11 77
Disable the weekends on datepicker control 6 52
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

752 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