how do i return arraylist from a function?
Posted
by KoolKabin
on Stack Overflow
See other posts from Stack Overflow
or by KoolKabin
Published on 2010-06-06T12:25:43Z
Indexed on
2010/06/06
12:32 UTC
Read the original article
Hit count: 388
Hi guys, I learnt example from msdn to populate a listbox control with arraylist. http://msdn.microsoft.com/en-us/library/1818w7we(v=VS.100).aspx
I want to create a function which will give return the USStates arraylist and use the returned value as datasource for listbox1
Dim USStates As New ArrayList()
USStates.Add(New USState("Alabama", "AL"))
USStates.Add(New USState("Washington", "WA"))
USStates.Add(New USState("West Virginia", "WV"))
USStates.Add(New USState("Wisconsin", "WI"))
USStates.Add(New USState("Wyoming", "WY"))
ListBox1.DataSource = USStates
ListBox1.DisplayMember = "LongName"
ListBox1.ValueMember = "ShortName
I tried creating a function like:
Public Shared Function FillList() As ArrayList()
Dim USStates As New ArrayList()
USStates.Add(New USState("Alabama", "AL"))
USStates.Add(New USState("Washington", "WA"))
USStates.Add(New USState("West Virginia", "WV"))
USStates.Add(New USState("Wisconsin", "WI"))
USStates.Add(New USState("Wyoming", "WY"))
return usstates
end function
but it says error: Value of type 'System.Collections.ArrayList' cannot be converted to '1-dimensional array of System.Collections.ArrayList'.
© Stack Overflow or respective owner