Hitos
Hitos

Reputation:

Convert ListBox.ObjectCollection to String array in VB.NET

I'm programming an application in VB.NET in which I need to take the Items from a ListBox, which are an ListBox.ObjectCollection and convert into a String array to be passed as a parameter to a Sub procedure. How should I do it?

Upvotes: 1

Views: 7008

Answers (2)

Benjamin Swedlove
Benjamin Swedlove

Reputation: 23

Updating for .NET 4.6

(From item In yourListBox.Items Select value = item.ToString).ToArray()

Upvotes: 0

Pavel Minaev
Pavel Minaev

Reputation: 101555

Assuming .NET 3.5, and thus LINQ:

(From item As Object In yourListBox.ObjectCollection Select item.ToString()).ToArray()

This also assumes that the way you want to convert items to strings is via ToString() - but, of course, you can replace it with anything else

Upvotes: 4

Related Questions