Results 1 to 14 of 14

Thread: Tree Node Problem

  1. #1
    New Member
    Join Date
    Sep 12
    Posts
    7

    Tree Node Problem

    I am going to try to make an application for a game called Tibia. Now im building a Quest Helper. When you click a node it loads a text file for that node and projects it into a text doc to the right of the nodes to give the tips.

    So heres what i have:

    Code:
    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.TreeView1.Nodes.Add("Rook")
            Me.TreeView1.Nodes.Add("Bear Room")
            Me.TreeView1.Nodes.Add("Captn Iglues Treasure")
            Me.TreeView1.Nodes.Add("Combat Knife")
            Me.TreeView1.Nodes.Add("Doublet")
            Me.TreeView1.Nodes.Add("Dragon Corpse")
            Me.TreeView1.Nodes.Add("Goblin Temple")
            Me.TreeView1.Nodes.Add("Katana")
            Me.TreeView1.Nodes.Add("Minotaur")
            Me.TreeView1.Nodes.Add("----------------------------")
            Me.TreeView1.Nodes.Add("Main")
    
        End Sub
    Now i want it so when say Node Bear Room is clicked it loads into RichTextBox1


    Any suggestions? I know it should be pretty basic but I am having a brain fart that has lasted 3 days now :s Any help would be greatly appreciated

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 02
    Location
    Bristol, UK
    Posts
    35,548

    Re: Tree Node Problem

    Welcome to VBForums

    Thread moved from the 'CodeBank VB6' forum (which is for you to post working code examples, not questions) to the 'VB.Net' (VB 2002 and later) forum

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,465

    Re: Tree Node Problem

    Er yeah ... pretty simple ...

    RichTextBox1.Text = e.Node.Text
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  4. #4
    New Member
    Join Date
    Sep 12
    Posts
    7

    Re: Tree Node Problem

    Naw like i want my Bear Room quest to have a text file with a detailed list of how to do that quest. So a text file to load when the Bear Room quest is clicked.

  5. #5
    Frenzied Member
    Join Date
    Sep 06
    Posts
    1,235

    Re: Tree Node Problem

    Add dunfiddlin's code under AfterSelect event
    Code:
        Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
            RichTextBox1.Text = e.Node.Text
        End Sub

  6. #6
    New Member
    Join Date
    Sep 12
    Posts
    7

    Re: Tree Node Problem

    Ik but all that does is prints the words of the node selected. I have a text file named BearRoomQuest.txt I want it so when bear room node is selected that the BearRoomQuest.txt is loaded into the text box

  7. #7
    Frenzied Member
    Join Date
    Sep 06
    Posts
    1,235

    Re: Tree Node Problem

    Quote Originally Posted by athenso View Post
    Ik but all that does is prints the words of the node selected. I have a text file named BearRoomQuest.txt I want it so when bear room node is selected that the BearRoomQuest.txt is loaded into the text box
    To do that, you have to save the path to the file with the node while you populate the tree, use Node's Tag property to save the file path, e.g.
    Code:
        Private Sub Form2_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            Dim tvNode As TreeNode
            tvNode = TreeView1.Nodes.Add("Rook")
            tvNode.Tag = "path to Rook.txt"
            tvNode = TreeView1.Nodes.Add("Bear Room")
            tvNode.Tag = "path to Bear Room.txt"
            ' add the rest.
        End Sub
    Then in AfterSelect event
    Code:
        Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
            RichTextBox1.LoadFile(e.Node.Tag)
        End Sub

  8. #8
    New Member
    Join Date
    Sep 12
    Posts
    7

    Re: Tree Node Problem

    Well it works but its not recognizing my path. The files are infact in that path.

    Code:
        Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim tvNode As TreeNode
            tvNode = TreeView1.Nodes.Add("Rook")
            tvNode.Tag.Rook = "D:\Tibia Tool\Quests\ExampleQuest.txt"
            tvNode = TreeView1.Nodes.Add("Bear Room")
            tvNode.Tag.Bear_Room = "D:\Tibia Tool\Quests\ExampleQuest2.txt"
        End Sub
    
        Private Sub QuitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles QuitToolStripMenuItem.Click
            Me.Close()
            Form1.Close()
        End Sub
    
    
        Private Sub TreeView1_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles TreeView1.AfterSelect
            RichTextBox1.LoadFile(e.Node.Tag)
    
    
    
        End Sub

  9. #9
    Frenzied Member
    Join Date
    Sep 06
    Posts
    1,235

    Re: Tree Node Problem

    What is that tvNode.Tag.Bear_Room = "D:\Tibia Tool\Quests\ExampleQuest2.txt"? It should be tvNode.Tag = "D:\Tibia Tool\Quests\ExampleQuest2.txt"

  10. #10
    New Member
    Join Date
    Sep 12
    Posts
    7

    Re: Tree Node Problem

    so i removed it and now it says file format is not valid.

  11. #11
    Frenzied Member
    Join Date
    Sep 06
    Posts
    1,235

    Re: Tree Node Problem

    Quote Originally Posted by athenso View Post
    so i removed it and now it says file format is not valid.
    Your main problem has been resolved, this is another issue!

    The file must contains plain text or RTF text. What the program you have used to create that file? It should be Notepad, Wordpad or similar.

  12. #12
    New Member
    Join Date
    Sep 12
    Posts
    7

    Re: Tree Node Problem

    notepad ++ its saved as a .txt

  13. #13
    Frenzied Member
    Join Date
    Sep 06
    Posts
    1,235

    Re: Tree Node Problem

    Quote Originally Posted by athenso View Post
    notepad ++ its saved as a .txt
    RichTextBox1.LoadFile expect RTF not plain text, so replace with
    Code:
        Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
            RichTextBox1.Text = IO.File.ReadAllText(e.Node.Tag)
        End Sub

  14. #14
    New Member
    Join Date
    Sep 12
    Posts
    7

    Re: Tree Node Problem

    perfect thank you much appreciated

Posting Permissions

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