Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

update textbox with List<string>

Posted on 2011-09-30
3
Medium Priority
?
310 Views
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?
0
Comment
Question by:Tom Knowlton
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
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>();
            values.Add("cat");
            values.Add("dog");
            values.Add("fish");

            textBox1.Lines = values.ToArray();

            // or

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

            // or

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

Open in new window

0
 
LVL 5

Author Closing Comment

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

Author Comment

by:Tom Knowlton
ID: 36903570
FOR MY REFERENCE:

        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 + " -->";
                    lsmarkup.Add(tempmarkup);    
                    lscss.Add("." + tempname + cssbody);
                    //textBoxCSS.Text += "." + tempname + cssbody;                
                }
                else
                {
                    string tempnameextra = controlname + "A" + (i - 25).ToString();
                    string tempmarkupextra = "<div id='" + tempnameextra + "' class='" + tempnameextra + "'></div><!-- end of div " + tempnameextra + " -->";

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




            textBoxMarkup.Lines = lsmarkup.ToArray();

            textBoxCSS.Lines = lscss.ToArray();
        }

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

963 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