Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Richtextbox -> ListBox

Richtextbox -> ListBox

Scheduled Pinned Locked Moved C#
helptutorial
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stathread
    wrote on last edited by
    #1

    I have a problem when I try to copy the richtextbox text to the items in a listbox. Is there a way to stop it from placing the entire richtextbox text as 1 item. below is an example of what I mean. http://img456.imageshack.us/img456/1223/listbox8al.png

    C 1 Reply Last reply
    0
    • S Stathread

      I have a problem when I try to copy the richtextbox text to the items in a listbox. Is there a way to stop it from placing the entire richtextbox text as 1 item. below is an example of what I mean. http://img456.imageshack.us/img456/1223/listbox8al.png

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Split the string on \r or \n, whichever is the delimiter that's causing the boxes you see. You need to split the string, then insert it one line at a time. Christian Graus - Microsoft MVP - C++

      S 1 Reply Last reply
      0
      • C Christian Graus

        Split the string on \r or \n, whichever is the delimiter that's causing the boxes you see. You need to split the string, then insert it one line at a time. Christian Graus - Microsoft MVP - C++

        S Offline
        S Offline
        Stathread
        wrote on last edited by
        #3

        I did this and it seems to not be working, im stuck. myRTF = richTextBox1.Rtf; while (myRTF.Length > 0) { //Find the index of the RTF Return Character int index = myRTF.IndexOf("\r\n"); //Extract the RTF to that point string temp = myRTF.Substring(0, index); //Trim the extracted part of the RTF myRTF = myRTF.Substring(index, myRTF.Length - index); //Add the item to your list box listBox1.Items.Add(temp); }

        C 1 Reply Last reply
        0
        • S Stathread

          I did this and it seems to not be working, im stuck. myRTF = richTextBox1.Rtf; while (myRTF.Length > 0) { //Find the index of the RTF Return Character int index = myRTF.IndexOf("\r\n"); //Extract the RTF to that point string temp = myRTF.Substring(0, index); //Trim the extracted part of the RTF myRTF = myRTF.Substring(index, myRTF.Length - index); //Add the item to your list box listBox1.Items.Add(temp); }

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          This is C#, your string class has a split method. Try splitting on just \r, or just \n. The boxes you get in your list box make me think the rich text control is returning one of those two, and not both. So, call the split method and get a string array, use for each to pass them into the list box. Christian Graus - Microsoft MVP - C++

          S 1 Reply Last reply
          0
          • C Christian Graus

            This is C#, your string class has a split method. Try splitting on just \r, or just \n. The boxes you get in your list box make me think the rich text control is returning one of those two, and not both. So, call the split method and get a string array, use for each to pass them into the list box. Christian Graus - Microsoft MVP - C++

            S Offline
            S Offline
            Stathread
            wrote on last edited by
            #5

            I did try to do the split on just /n or /r but no luck?

            C 2 Replies Last reply
            0
            • S Stathread

              I did try to do the split on just /n or /r but no luck?

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Just a sec, I'll whip up a project for you Christian Graus - Microsoft MVP - C++

              S 1 Reply Last reply
              0
              • C Christian Graus

                Just a sec, I'll whip up a project for you Christian Graus - Microsoft MVP - C++

                S Offline
                S Offline
                Stathread
                wrote on last edited by
                #7

                Thanks..

                1 Reply Last reply
                0
                • S Stathread

                  I did try to do the split on just /n or /r but no luck?

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  Your slash is the wrong way around. This works: string text = richTextBox1.Text; string [] strings = text.Split('\n'); foreach (string s in strings) { if (s.Length > 0) listBox1.Items.Add(s); } Christian Graus - Microsoft MVP - C++

                  S 1 Reply Last reply
                  0
                  • C Christian Graus

                    Your slash is the wrong way around. This works: string text = richTextBox1.Text; string [] strings = text.Split('\n'); foreach (string s in strings) { if (s.Length > 0) listBox1.Items.Add(s); } Christian Graus - Microsoft MVP - C++

                    S Offline
                    S Offline
                    Stathread
                    wrote on last edited by
                    #9

                    You own man, thanks a bunch!! Ron

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups