retrieving the items of listbox...
I need to retrieve the items of a Listbox and assign they to an array. Somebody knows How to do this?
Thanks in advanced
I need to retrieve the items of a Listbox and assign they to an array. Somebody knows How to do this?
Thanks in advanced
Jack2005_MSFT wrote:
Dim myItems As New ArrayList()For Each i As String In Me.ListBox1.Items myItems.Add(i)
Next
again. . .
load the strings into an arraylist first. . .
then just do
ListBox1.DataSource = MyArrayList
quit moving collections around. . . load them one place and bind your controls to them.
Because I can't stand vb and refuse to code in it unless I am getting paid. . . god what a dog. . . this is in C#
List<string> _stringList = new List<string>();private void Form1_Load(object sender, EventArgs e)
{
_stringList.AddRange(new String[] {"foo","bar"});
listBox1.DataSource = _stringList;
}
Blair it's nice to see you again. ![]()
Please DO NOT start the VB stuff. If you don't like VB, I have a really good piece of advice. Stay out of VB fora and you won't be bothered. I won't go in C forum and criticize their language, ok?
And how about not posting C# in a VB Forum?
P.S. Tell BSDetector, I said hello!
Blair Allen Stark wrote:
Because I can't stand vb and refuse to code in it unless I am getting paid. . . god what a dog. . . this is in C#
There is no need for that attitude, C# and VB.NET code gets compiled into same IL assembly. There is no need to express your dislike for VB.
I agree that you should not create new collections but reuse existing collections. I also converted the C# code to VB.
' Create list of strings
Dim _stringList As New List(Of String)(New String() {"foo", "bar"})
' Use list of strings as source for a ListBox control
ListBox1.DataSource = _stringList