Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Suppose for example there is a combobox that contains these items:
My Name
Your Name
Their Name
Our Name
 
I want to put these lines into a textbox, and I am using this code:
for i = 1 to Mycombobox.items.count
    mytextbox.lines(i) = Mycombobox.items(i)
next
 
This, however, does not work.
Posted 28-Apr-11 11:02am
Loek61120
Edited 28-Apr-11 11:07am
AspDotNetDev191.5K
v3
Comments
AspDotNetDev at 28-Apr-11 16:08pm
   
I updated your question. I guessed that you are working with VB.NET. Feel free to make changes if I edited out anything essential. Also, please let us know what you mean by "it does not work".
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

in c# it would be like
 
textBox1.Multiline = true;
            StringBuilder sb=new StringBuilder();
            foreach (string item in comboBox1.Items)
            {
                sb.Append(item);
                sb.AppendLine();
            }
            textBox1.Text = sb.ToString();
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Here's Albin's C# converted to VB:
 
textBox1.Multiline = True
Dim sb As New StringBuilder()
For Each item As String In comboBox1.Items
  sb.Append(item)
  sb.AppendLine()
Next item
textBox1.Text = sb.ToString()
 
And here's your code fixed:
 
mytextbox.Multiline = True
 
For i = 1 to Mycombobox.Items.Count
    mytextbox.Lines(i - 1) = Mycombobox.Items(i - 1)
Next
 
Take your pick!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Try like this:
 
    Dim n as integer;
    n = Mycombobox.Items.Count;
    Dim lines(n) as string;
    mytextbox.Lines = lines;
    for i = 1 to Mycombobox.Items.Count
        mytextbox.lines(i) = Mycombobox.Items(i).ToString();
    next
 
You have to forgive my VB.NET code as I'm not well acquainted with VB. I hope you understand though what I'm trying to express.
 
Best Regards,
 
-MRB
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 230
2 BillWoodruff 205
3 Sergey Alexandrovich Kryukov 195
4 DamithSL 165
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,650
3 Kornfeld Eliyahu Peter 3,460
4 Sergey Alexandrovich Kryukov 2,811


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 28 Apr 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100