Results 1 to 10 of 10

Thread: Treeview Questions

  1. #1

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435

    Treeview Questions

    I have a treeview and i wish to see which node the user's selected. I know you can use e.node.text but the text can be subject to change so is there any other way to check, like using the tag? How do I set the tag for each indvidual node?
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    VB Code:
    1. Private Sub TreeView1_AfterSelect(ByVal sender As System.Object _
    2.     , ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
    3.  
    4. MsgBox(TreeView1.SelectedNode().ToString)
    5. End Sub

    this way no matter the node caption is , try to figure it out !
    (I've never worked with Treeview since 2 years)

  3. #3

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    It does work, but it returns the text of the node, like e.node.text. I have text like "Save or append text to a file" and i want something like:

    VB Code:
    1. if user has selected this node then
    2.    do this
    3. end if
    but I don't want to check for "Save or append text to a file" as this text could change, i want to check for something simple like the tag property, something like f1 or f2 for File Handling, or vfx1 or vfx2 for Visual FX, as these wouldn't change.

    I think it's time to start revising Treeview's pirate
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    try this
    VB Code:
    1. Dim treev As New TreeNode()
    2.     Dim i As Integer
    3.  
    4.     Private Sub TreeView1_AfterSelect(ByVal sender As System.Object _
    5. , ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
    6.  
    7.         Select Case e.Node.Index = i
    8.             Case i = 0
    9.                 MsgBox("index 0 ")
    10.             Case i = 1
    11.                 MsgBox("index 1")
    12.             Case i = 2
    13.                                   'do the next  
    14.                                   End Select
    15. End Sub

  5. #5

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    Thanks again pirate, but.... (sorry) If i insert extra nodes then that will throw the index numbers out, I know there is a tag property but how do i set the tags for individual nodes?
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  6. #6
    Junior Member husain's Avatar
    Join Date
    Jul 2002
    Location
    United Arab Emirates
    Posts
    31
    I don't know if this is what you want.
    VB Code:
    1. ' Assume your treeview control is called TreeView1.
    2.  
    3. ' This bit of code goes in the Form_Load function.
    4. TreeView1.Nodes.Add("Node 1")
    5. TreeView1.Nodes.Add("Node 2")
    6. TreeView1.Nodes.Add("Node 3")
    7.  
    8. TreeView1.Nodes(0).Tag = "mynode1"
    9. TreeView1.Nodes(1).Tag = "mynode2"
    10. TreeView1.Nodes(3).Tag = "mynode3"
    11.  
    12. ' And this goes in the TreeView1_AfterSelect function.
    13. MessageBox.Show("You selected " & TreeView.SelectedNode.Tag())

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    the first three lines will generate three nodes at runtime , so you could left them out and everything will goes fine.
    nice try by the way

  8. #8

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    Thanks, i'll try that.

    Another Treeview question:

    I want my program to create a Treeview by reading a directory, any directories in that, and then any files inside those directories.

    Basically, I'd like to program to create it's own treeview. The Main Directory is set (it's called Code) but then i'd like to program to look inside the Code directory and make a treeview of what's in there.

    This is way above my head but there might be a kind soul out there
    Last edited by RealNickyDude; Jan 4th, 2003 at 05:56 AM.
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  9. #9

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    Anyone help? I can't continue with the VBCodebook .NET otherwise
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  10. #10

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    Anyone?
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

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