Results 1 to 5 of 5

Thread: Access System.Windows.Forms component

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2003
    Posts
    52

    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
    Last edited by jonni; Dec 11th, 2006 at 05:33 AM.

  2. #2
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    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.
    Show Appreciation. Rate Posts.

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2003
    Posts
    52

    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

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2003
    Posts
    52

    Re: Access System.Windows.Forms component

    Anyone?

    /Jonni

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width