Link to home
Start Free TrialLog in
Avatar of Peter Kiers
Peter KiersFlag for Netherlands

asked on

Get all the strings of a stringlist in a textbox.

Hi, I have this code below to display all the string of a stringlist in a textbox.
But even thou there are more strings in the stringlist I only get one string
displayed in the textbox. What do I do wrong?

private List<string> opened = new List<string>();

private void button1_click(object sender, EventArgs e)
{
       foreach (string mylist in opened)
       {
        testking.Text=mylist;
       }
}

Open in new window


Greetings, Peter Kiers
Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

Each time you are looping you are overwriting the Textbox value.
try something like:
private List<string> opened = new List<string>();

private void button1_click(object sender, EventArgs e)
{
       foreach (string mylist in opened)
       {
            if (testking.Text = string.Empty)
            {
                 testking.Text=mylist;
            }
            else
            {
                 testking.Text = testKing.Text + " " + mylist;
            }
       }
}

Open in new window

Avatar of Peter Kiers

ASKER

Hi, thank you for the response. I get: Cannot implicitly convert 'type' to 'bool' at the IF-line

P
Oh got it must be ==

Peter
Is it possible to display the strings underneath each other then next to each other.

Peter
ASKER CERTIFIED SOLUTION
Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks. Peter