0

Hi everyone
I am trying to display a listbox(list of Column Names selected from a table in database)into a textbox displaying like a CSV file format.
Please be notice that I do not want to create a CSV file, as I said I just like to pass items from listbox into a Textbox in a comma seperated format.
lets say I have a listbox populated like:

lstCols.Items.Add("Name");
lstCols.Items.Add("ID");
lstCols.Items.Add("Age");
lstCols.Items.Add("City");

Now how I can display the above list in a text box like

Name, ID, Age, City

I realy appreciate your time in advance

Edited by Behseini: n/a

3
Contributors
3
Replies
12
Views
6 Years
Discussion Span
Last Post by abelLazm
1
for(int i = 0; i< lstCols.Items.Count; i++)
{
    if((i +1) < lstCols.Count)
        textBox1.Text += lstCols.Items[i] + ", ";
    else
       textBox1.Text += lstCols.Items[i];
}
Votes + Comments
Perfect answer
0

Thanks

but I just modify your code a little bit on

if((i +1) < lstCols.Count)

to:

for(int i = 0; i<listBox1.Items.Count; i++)
{
 if((i +1) < listBox1.Items.Count)
 textBox1.Text += listBox1.Items[i] + ", ";
 else
 textBox1.Text += listBox1.Items[i];
}

Thanks again and appreciate for your time

Edited by Behseini: n/a

0

Thanks

but I just modify your code a little bit on

if((i +1) < lstCols.Count)

to:

for(int i = 0; i<listBox1.Items.Count; i++)
{
 if((i +1) < listBox1.Items.Count)
 textBox1.Text += listBox1.Items[i] + ", ";
 else
 textBox1.Text += listBox1.Items[i];
}

Thanks again and appreciate for your time

No problem it was just a typing error logic was right....

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.