Share via


Add multiple items to a listbox in VB.NET

Question

Saturday, August 16, 2014 6:22 PM

How do you add a range of items to a listbox with VB.NET code?

I've come up with the code below, but it doesn't seem to work as "it can't handle the New statement"...

ListBox1.Items.AddRange(New String From {"text", "text2", "text3"})

Can anyone solve this problem?

JDS404 Check out my blog at www.interlinkjds.wordpress.com!

All replies (2)

Saturday, August 16, 2014 7:24 PM âś…Answered

Try this syntax:

*    ListBox1.Items.AddRange({"text", "text2", "text3"})*

or       

*    ListBox1.Items.AddRange(New String() {"text", "text2", "text3"})*

or

*    ListBox1.DataSource = {"text", "text2", "text3"}*


Saturday, August 16, 2014 7:25 PM

Try this syntax:

*    ListBox1.Items.AddRange({"text", "text2", "text3"})*

or       

*    ListBox1.Items.AddRange(New String() {"text", "text2", "text3"})*

       

Thanks - it all works!

JDS404 Check out my blog at www.interlinkjds.wordpress.com!