|
-
Sep 7th, 2012, 05:34 PM
#1
Thread Starter
New Member
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
-
Sep 9th, 2012, 09:35 AM
#2
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
-
Sep 9th, 2012, 05:17 PM
#3
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!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
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!
-
Sep 9th, 2012, 07:16 PM
#4
Thread Starter
New Member
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.
-
Sep 9th, 2012, 07:29 PM
#5
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
-
Sep 9th, 2012, 07:31 PM
#6
Thread Starter
New Member
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
-
Sep 9th, 2012, 07:42 PM
#7
Re: Tree Node Problem
 Originally Posted by athenso
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
-
Sep 9th, 2012, 07:54 PM
#8
Thread Starter
New Member
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
-
Sep 9th, 2012, 08:00 PM
#9
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"
-
Sep 9th, 2012, 08:04 PM
#10
Thread Starter
New Member
Re: Tree Node Problem
so i removed it and now it says file format is not valid.
-
Sep 9th, 2012, 08:12 PM
#11
Re: Tree Node Problem
 Originally Posted by athenso
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.
-
Sep 9th, 2012, 08:13 PM
#12
Thread Starter
New Member
Re: Tree Node Problem
notepad ++ its saved as a .txt
-
Sep 9th, 2012, 08:24 PM
#13
Re: Tree Node Problem
 Originally Posted by athenso
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
-
Sep 9th, 2012, 08:26 PM
#14
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|