Access System.Windows.Forms component
Hi All,
What's the different between a treeView declared like:
Code:
this.treeView1 = new System.Windows.Forms.TreeView();
and a treeNode declared like:
Code:
System.Windows.Forms.TreeNode treeNode10 = new System.Windows.Forms.TreeNode("Rond 1");
I found out how to access the TreeNode:
Code:
TreeNode tn1 = this.treeView1.Nodes[0];
But why can I access a node declared like this in a different class than the form class:
Code:
System.Windows.Forms.TreeNode treeNode666 = new System.Windows.Forms.TreeNode("Kalle");
treeNode666.Text = "Stig";
But not in the form class where the node is declared in the Form1.Designer.cs class like this:
Code:
System.Windows.Forms.TreeNode treeNode10 = new System.Windows.Forms.TreeNode("Rond 1");
And I want to access the Node I as I did above:
Code:
treeNode10.Text = "Stig";
Why does it work in the other class, but in the form class where I get 'The name 'treeNode10' does not exist in the current context' error?
Regards
Jonni
Re: Access System.Windows.Forms component
Are you sure?? It is working for me, no compiler error.
Please post the whole code you are using.
Re: Access System.Windows.Forms component
This code (in Form1.cs) works:
Code:
private void button4_Click(object sender, EventArgs e)
{
TreeNode tn1 = this.treeView1.Nodes[0];
logic1.changeTreeNode(ref tn1);
}
This code (in Form1.cs) DOESN'T work:
Code:
private void button4_Click(object sender, EventArgs e)
{
TreeNode tn1 = treeNode10;
logik1.ÄndraTräd(ref tn1);
}
Where treeNode10 is declared in Form1.Designer.cs:
Code:
System.Windows.Forms.TreeNode treeNode10 = new System.Windows.Forms.TreeNode("Rond 1");
this.treeView1 = new System.Windows.Forms.TreeView();
this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {treeNode10});
My main question is why is treeView declared as
Code:
this.treeView1 = new System.Windows.Forms.TreeView();
and treeNode10 declared as:
Code:
System.Windows.Forms.TreeNode treeNode10 = new System.Windows.Forms.TreeNode("Rond 1");
Both the treeView and the treeNode is added at designtime in designview.
/Jonni
Re: Access System.Windows.Forms component
Re: Access System.Windows.Forms component
This is NOT a declaration:
Code:
this.treeView1 = new System.Windows.Forms.TreeView();
treeNode10 is declared as a local variable, so it doesn't exist outside the method in which it's declared.