[2008] Help with TreeView
Hi, i'm trying to use the treeview to display the text of a rtf (rich text file) file when an specific node if clicked.
Home
OMG
WOOT
For example, if i pick OMG, i want the text of lol.rtf to be displayed on a richtextbox. But somehow i just can't manage to get it... I know to import the text of a .txt file to a textbox, but using the treeview makes it more complicated.
This is the code im using right now:
Code:
Private Sub TreeView1_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick
Select Case e.Node.Index
Case 0
Dim file As String
file = My.Computer.FileSystem.ReadAllText(filename)
RichTextBox1.Text = file
Case 1
'Same code, different file name
Case 2
'Same code, different file name
Case 3
'Same code, different file name
Case 4
'Same code, different file name
End Select
End Sub
Another thing is, that i can't import the *.rtf text into a richtextbox and i don't know why.
Re: [2008] Help with TreeView
To import an rtf into RTB try this
vb Code:
Dim strfilename As String
With OpenFileDialog1
.Filter = "RICHTEXT FILES (*.rtf) |*.rtf"
.FilterIndex = 1
.InitialDirectory = "c:\"
.Title = "OPEN FILE"
.FileName = ""
End With
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
strfilename = OpenFileDialog1.FileName
Dim OBJREADER As StreamReader = New StreamReader(STRFILENAME)
richTextBox1.Text = OBJREADER.ReadLine
End If
Re: [2008] Help with TreeView
Yeah, it KINDA worked, because it only imported a bunch of gibberish. It's probably the file.
Re: [2008] Help with TreeView
To read RTF into a RichTextBox you need to do;
RichTextBox1.LoadFile(FileName, RichTextBoxStreamType.RichText)