How to Return a Value in a Multi Column Listbox
- 1). Launch Microsoft Visual Studio, click "New Project" from the left pane of the screen and expand "Visual Basic" below "Installed Templates." Click "Windows" and double-click "Windows Forms Application" from the center of the dialog window to create a new project.
- 2). Double-click "ListBox" to add a new list box control to your form. Double-click "Button" to add a new button to your form. Add a second button to your form using the same technique.
- 3). Double-click "Button1" to create a click event and add the following code to populate the "ListBox" control with items in multiple columns:
ListBox1.MultiColumn = True
ListBox1.SelectionMode = SelectionMode.MultiExtended
For iCntr As Integer = 0 To 19
ListBox1.Items.Add("Item " & iCntr.ToString())
Next iCntr - 4). Switch back to the form design and double-click "Button2" to create a click event for this button. Add the following code to return the item value selected from any column:
Dim myItem As String
Dim selItem As String
For Each myItem In ListBox1.SelectedItems
selItem = myItem.ToString() & " "
Next
MessageBox.Show("The item selected is: " & selItem) - 5). Press "F5" to run the program and click "Button1." Click "Button2" to display a message box with the item selected.
Source...