Solved

adding a node to the selected node of a treeview

Posted on 2010-11-10
5
903 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 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