[VB.NET] ListBox Items to TextBox?

Jordy1212
Jordy1212 used Ask the Experts™
on
I've been having all types of problems with listboxs today. What I'm trying to do is add each item in the listbox to a richtextbox. My code only seems to add 1 item instead of ALL the items

     
For Each item As String In lstMusic.Items

            RichTextBox1.Text = item

        Next

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
anyone?
Top Expert 2006
Commented:
concatenate richtextbox

do you want it as one line or on different lines?


For Each item As String In lstMusic.Items

    if RichTextBox1.Text <> "" then RichTextBox1.Text = RichTextBox1.Text & ";"
    RichTextBox1.Text = RichTextBox1.Text & item

Next
Jaime OlivaresSoftware Architect
Top Expert 2008
Commented:
try with the following:

RichTextBox1.Text = ""
For Each item As String In lstMusic.Items
            RichTextBox1.Text = RichTextBox1.Text & item
Next
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Top Expert 2006

Commented:
If you want it per line replace   ";"   with   vbcrlf
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
*Setting RichTextBox1.Text = ~something~ for concatenation purposes will REMOVE any previous formatting you had in the RTB...  =\

Move the selection to the end and set SelectedText() instead:
For Each item As String In lstMusic.Items
    RichTextBox1.SelectionStart = RichTextBox1.TextLength
    RichTextBox1.SelectedText = item & vbCrLf
Next

Open in new window

      For Each item As String In lstMusic.Items
            RichTextBox1.AppendText(item & vbCrLf)
        Next

Author

Commented:
Thank you all

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial