VB.Net Help (TreeView Control)

Discussion in 'OT Technology' started by Tk, Dec 26, 2002.

  1. Tk

    Tk Well-Known Member

    Joined:
    Dec 23, 2001
    Messages:
    23,086
    Likes Received:
    285
    Location:
    nw iowa
    I'm trying to add a root node to a treeview control on another form.

    Code:
            Dim MainFrm As New MainFrm()
            Dim newNode As TreeNode = New TreeNode("Text")
            MainFrm.ProjectTree.Nodes.Add(newNode)
    
    this doesnt error, but nothing is added to the treeview in MainFrm.

    note: this is the first vb.net program im making :sad2:
     
  2. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    you need to get the reference to the main form, not create a new instance of it. Make the Treeview control on that form public and access it like that. Is this an MDI document?
     
  3. Tk

    Tk Well-Known Member

    Joined:
    Dec 23, 2001
    Messages:
    23,086
    Likes Received:
    285
    Location:
    nw iowa
    no mdi, just a seperate form. i'll give that a try... all of this is different than vb v6!
     
  4. Tk

    Tk Well-Known Member

    Joined:
    Dec 23, 2001
    Messages:
    23,086
    Likes Received:
    285
    Location:
    nw iowa
    where do i go in the properties to make it public?

    edit: modifiers -> public im guessing
     
  5. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    yes. Try that. Also, what type of sub form is it? Dialog? or Form?
     
  6. Tk

    Tk Well-Known Member

    Joined:
    Dec 23, 2001
    Messages:
    23,086
    Likes Received:
    285
    Location:
    nw iowa
    just a regular form.

    how do i make a reference to MainFrm from the AddRoot form? I took out the top line of that statement and it just says "Reference to a non-shared member requires an object reference"
     
  7. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    Try using the .Parent property of your current form, that would be a reference to the previous form that opened the child form.
     
  8. Tk

    Tk Well-Known Member

    Joined:
    Dec 23, 2001
    Messages:
    23,086
    Likes Received:
    285
    Location:
    nw iowa
    im off to lunch ill mess around with it when i get back :sad2:
     
  9. Tk

    Tk Well-Known Member

    Joined:
    Dec 23, 2001
    Messages:
    23,086
    Likes Received:
    285
    Location:
    nw iowa
    In the AddRoot form I place AddRoot.Parent() in the btnAdd_Click statement.

    It underlines in blue and says "Reference to a non-shared member requires an object reference."

    theres to much referencing and shit with this. VB6 was a lot easier, simply mainfrm.tree.nodes.add("nodetext") and your done.

    :mad:
     
  10. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    not the parent of the AddRoot. The parent of the current form. Try Me.Parent.TreeControl.AddRoot(). That may work if it is already casted. Have you tried just referencing the form directly? MainFrm.TreeControl.AddRoot() ?

    If you want to upload the project somewhere so i can download it, i may be able to look at it for you. Most of my .NET work is with C# and on the web, not windows, but i'm sure i could figure it out. Some of my co-workers are working with the windows stuff too.
     

Share This Page