Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


update textbox with List<string>

Posted on 2011-09-30
Medium Priority
Last Modified: 2012-06-21
In a windows application (C# / VS 2010 Prof) , is there a way to update a textbox with the contents of a List<string> object all at once, instead of looping through the List<string> and adding the strings to the textbox one by one?

Also, is there a way to not update the textbox while it is being updated?
Question by:Tom Knowlton
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
  • 2
LVL 86

Accepted Solution

Mike Tomlinson earned 2000 total points
ID: 36894807
You can use ToArray() on the List and pass that to String.Join() with a separator.  Or you can just set the Lines() property:
private void button1_Click(object sender, EventArgs e)
            List<string> values = new List<string>();

            textBox1.Lines = values.ToArray();

            // or

            textBox1.Text = String.Join(", ", values.ToArray());

            // or

            textBox1.Text = String.Join(Environment.NewLine, values.ToArray());

Open in new window


Author Closing Comment

by:Tom Knowlton
ID: 36903557
It's tons faster now, too, thanks!

Author Comment

by:Tom Knowlton
ID: 36903570

        private void buttonCalcDivs_Click(object sender, EventArgs e)
            List<string> lsmarkup = new List<string>();
            List<string> lscss = new List<string>();

            int maxdivs = Convert.ToInt32(textBoxHowMany.Text);
            int newnamemarker = maxdivs - 26;
            string controlname = textBoxControlName.Text;
            textBoxMarkup.Text = "";
            textBoxCSS.Text = "";
            const string cssbody = "{position:relative;float:left;}";

            for (int i = 0; i < maxdivs; i++)
                if(i < 26)
                    string tempname = controlname  + char.ConvertFromUtf32(i + 65);
                    string tempmarkup = "<div id='" + tempname + "' class='" + tempname + "' runat='server'></div><!-- end of div " + tempname + " -->";
                    lscss.Add("." + tempname + cssbody);
                    //textBoxCSS.Text += "." + tempname + cssbody;                
                    string tempnameextra = controlname + "A" + (i - 25).ToString();
                    string tempmarkupextra = "<div id='" + tempnameextra + "' class='" + tempnameextra + "'></div><!-- end of div " + tempnameextra + " -->";

                    lscss.Add("." + tempnameextra + cssbody);
                    //textBoxCSS.Text += "." + tempnameextra + cssbody;                

            textBoxMarkup.Lines = lsmarkup.ToArray();

            textBoxCSS.Lines = lscss.ToArray();

Open in new window


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

722 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