Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
3.33/5 (3 votes)
See more:
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:
VB.NET
for i = 1 to Mycombobox.items.count
    mytextbox.lines(i) = Mycombobox.items(i)
next


This, however, does not work.
Posted
Updated 28-Apr-11 10:07am
v3
Comments
AspDotNetDev 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".

Try like this:

VB
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
 
Share this answer
 
Here's Albin's C# converted to VB:

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:

VB
mytextbox.Multiline = True

For i = 1 to Mycombobox.Items.Count
    mytextbox.Lines(i - 1) = Mycombobox.Items(i - 1)
Next


Take your pick!
 
Share this answer
 
in c# it would be like

C#
textBox1.Multiline = true;
            StringBuilder sb=new StringBuilder();
            foreach (string item in comboBox1.Items)
            {
                sb.Append(item);
                sb.AppendLine();
            }
            textBox1.Text = sb.ToString();
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900