Solved

Get all the strings of a stringlist in a textbox.

Posted on 2014-02-06
6
199 Views
Last Modified: 2014-02-06
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
0
Comment
Question by:peterkiers
  • 4
  • 2
6 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
Comment Utility
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

0
 
LVL 1

Author Comment

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

P
0
 
LVL 1

Author Comment

by:peterkiers
Comment Utility
Oh got it must be ==

Peter
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:peterkiers
Comment Utility
Is it possible to display the strings underneath each other then next to each other.

Peter
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
Comment Utility
You should be able to use Environment.NewLine instead of a space to separate the values:

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 + Environment.NewLine + mylist;
            }
       }
} 

Open in new window

0
 
LVL 1

Author Comment

by:peterkiers
Comment Utility
Thanks. Peter
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now