Results 1 to 9 of 9

Thread: add a button while running and how u use a treeview

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    add a button while running and how u use a treeview

    ok i got 2 questions... how do u add a button while the program is running, like for example u hit a button and it creates another 1.

    second how do u use a treeview i wanna do this.

    add a node then a node in the node so it looks like

    we
    |
    -we2
    +we3
    so when we is opened it shows we2

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

    Re: add a button while running and how u use a treeview

    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

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: add a button while running and how u use a treeview

    can u plz simplify the treeview one

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: add a button while running and how u use a treeview

    This might help.

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

    Re: add a button while running and how u use a treeview

    The simple fact is that the TreeView itself and every node in the TreeView has a Nodes property. If you want to add a node to the TreeView you call:
    VB Code:
    1. myTreeView.Nodes.Add(newTreeNode)
    If you want to add a node to an existing node you would call:
    VB Code:
    1. myTreeNode.Nodes.Add(newTreeNode)
    If you wanted to add a node to the first node in the TreeView you could do it like this:
    VB Code:
    1. myTreeView.Nodes(0).Nodes.Add(newTreeNode)
    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

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: add a button while running and how u use a treeview

    Quote Originally Posted by jmcilhinney
    The simple fact is that the TreeView itself and every node in the TreeView has a Nodes property. If you want to add a node to the TreeView you call:
    VB Code:
    1. myTreeView.Nodes.Add(newTreeNode)
    If you want to add a node to an existing node you would call:
    VB Code:
    1. myTreeNode.Nodes.Add(newTreeNode)
    If you wanted to add a node to the first node in the TreeView you could do it like this:
    VB Code:
    1. myTreeView.Nodes(0).Nodes.Add(newTreeNode)
    im trying to use this code

    VB Code:
    1. Dim ty2 As Long
    2.                 For ty2 = 0 To ListBox1.Items.Count - 1
    3.                     If ListBox1.Items.Item(ty2) = we Then
    4.                         TreeView1.Nodes(ty2).Nodes.Add(temp2)
    5.                     End If
    6.                 Next ty2

    but it has an error on TreeView1.Nodes(ty2).Nodes.Add(temp2)
    its fine if i do something like TreeView1.Nodes(0).Nodes.Add(temp2)

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

    Re: add a button while running and how u use a treeview

    If you read my signature you'll see that in my book "an error" doesn't cut it.
    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

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: add a button while running and how u use a treeview

    Quote Originally Posted by jmcilhinney
    If you read my signature you'll see that in my book "an error" doesn't cut it.
    does this help?
    Error 1 Overload resolution failed because no accessible 'Item' can be called without a narrowing conversion:
    'Public Overridable ReadOnly Default Property Item(key As String) As System.Windows.Forms.TreeNode': Argument matching parameter 'key' narrows from 'Long' to 'String'.
    'Public Overridable Default Property Item(index As Integer) As System.Windows.Forms.TreeNode': Argument matching parameter 'index' narrows from 'Long' to 'Integer'. C:\Documents and Settings\*****\Desktop\vb.net projects\tag viewer2\Form1.vb 132 25 tag viewer

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

    Re: add a button while running and how u use a treeview

    You should turn Option Strict On and then that code wouldn't even compile. It would give you a compile error telling you that you could not implicitly convert from a Long to an Integer. Is there a particular reason that you have chosen to use a Long? You index pretty much every collection with an Integer, and using the Integer type is more efficient than using a Long in general. Are you planning on having more than 2,147,483,648 nodes in your TreeView?

    With regards to Option Strict, it disallows late binding and implicit narrowing conversions, as you tried to make here. It will help catch many potential issues at design time rather than run time, which makes your code more robust. EVERY VB.NET developer should have it turned On ALWAYS.
    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