I have a list (returned from database) and I have a combo box which I am populating with a list, I am doing this because the ComboBox
can be populated from a range of data sources.
I need to convert the IList(Of Object)
into a List(Of String)
.
The Object
has an override on the ToString
method.
Please can anyone advise on this one?
If you have a
IList(Of Object)
, like this:You can add the items in that list to a
ComboBox
, directly, like this:There is no need to first convert it to a
List(Of String)
since theComboBox
automatically calls theToString
method for you on each item in the list. However, if you really need to convert it to aList(Of String)
, you can do it like this:Or, if you don't want to use the LINQ extension methods, you could do it the old-fashioned way, like this: