Adding string values to a listbox?
So I'm following a tutorial about VB for beginners, and one of the sections is where the guy assigns values to a listbox through its properties menu. He clicks the 3 dots next to "items" and just types all the options in.
I'm on a newer version though, and when I click on the 3 dots it doesn't let me type it all straight in - there's a dropdown menu for buttons, listbox items, etc. None of them work because apparently I can't convert a list item to a string, even though I used .SelectedOption
Am I looking in the wrong menu or something? How do I put a string into my listbox
5 comments · 93% upvoted · source · other discussions
It is always a better and more flexible option to add listbox values with code.
MyList.Items.ClearMyList.Items.Add ("Apples")MyList.Items.Add ("Oranges")MyList.Items.Add ("Bananas")If your items were into an array, you could use a shortcut such as :
Dim x() as String = {"Plumber", "Electrician", "Carpenter"}MyList.Items.AddRange(x)Put the necessary code into a subroutine, call that subroutine when loading the form.