Solved

update textbox with List<string>

Posted on 2011-09-30
3
299 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:knowlton
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 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:knowlton
ID: 36903557
It's tons faster now, too, thanks!
0
 
LVL 5

Author Comment

by: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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

13 Experts available now in Live!

Get 1:1 Help Now