Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 915
  • Last Modified:

adding a node to the selected node of a treeview

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
peterkiers
Asked:
peterkiers
  • 2
  • 2
2 Solutions
 
mkobrinCommented:
Try
n.Nodes.Add(n2.ToString(), NewText);
or
n.Nodes.Add(Convert.ToString(n2), NewText);
or
n.Nodes.Add(n2.Text, NewText);
0
 
mkobrinCommented:
Or if you want to add the node itself then
n.Nodes.Add(n2);
0
 
peterkiersAuthor Commented:
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
 
Carl TawnSystems and Integration DeveloperCommented:
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
 
peterkiersAuthor Commented:
Oke thanx.
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now