Question:
C# adding Strings to a list box. ?
David P
2008-09-12 21:11:35 UTC
I am more familiar with working with Java, but I am trying to work with C#.
What I am trying to do is very simple but I have no idea. I have a list box. What I am trying to do is simply add Strings to a list box in the code view (not in the design [property] view).
Any thoughts?
Four answers:
John O
2008-09-12 21:30:05 UTC
Put your strings in an array.



for(int i=0; i
listBox.Add(strArray[i]);

}



I haven't worked in C# for a while, so it could be something like listBox.Items.Add(). Check the API.
Big John Studd
2008-09-12 22:21:54 UTC
you have two ways, using an array:



string [] myStrings=new string[2]{"Hello","Bryan"};



foreach(string s in myStrings)

{

listBox1.Items.Add(s);

}





OR



for(int i=0; i < myStrings.Length; i++)

{

listBox1.Items.Add(myStrings[i]);

}
2013-12-19 00:21:31 UTC
listBox1.Items.Add("Sunday");

listBox1.Items.Add("Monday");

listBox1.Items.Add("Tuesday");



More info :



http://csharp.net-informations.com/gui/cs-listbox.htm c# listbox



douglas
?
2016-11-03 15:33:16 UTC
C Listbox


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...