Solved

Get all the strings of a stringlist in a textbox.

Posted on 2014-02-06
6
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 39840639
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
ID: 39840649
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
ID: 39840654
Oh got it must be ==

Peter
0
CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

 
LVL 1

Author Comment

by:peterkiers
ID: 39840658
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
ID: 39840671
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
ID: 39840675
Thanks. Peter
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

635 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