Results 1 to 4 of 4

Thread: [2008] Help with TreeView

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Exclamation [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.
    Last edited by tassa; Feb 28th, 2009 at 02:10 PM.
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [2008] Help with TreeView

    To import an rtf into RTB try this

    vb Code:
    1. Dim strfilename As String
    2. With OpenFileDialog1
    3.     .Filter = "RICHTEXT FILES (*.rtf) |*.rtf"
    4.     .FilterIndex = 1
    5.     .InitialDirectory = "c:\"
    6.     .Title = "OPEN FILE"
    7.     .FileName = ""
    8. End With
    9. If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
    10.     strfilename = OpenFileDialog1.FileName
    11.     Dim OBJREADER As StreamReader = New StreamReader(STRFILENAME)
    12.     richTextBox1.Text = OBJREADER.ReadLine
    13. End If
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: [2008] Help with TreeView

    Yeah, it KINDA worked, because it only imported a bunch of gibberish. It's probably the file.
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  4. #4
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: [2008] Help with TreeView

    To read RTF into a RichTextBox you need to do;

    RichTextBox1.LoadFile(FileName, RichTextBoxStreamType.RichText)

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