How to Code in ListBox
The Microsoft .NET "ListBox" control displays a list of items you set up from a database or a static list of string variables. The "Add" function appends an additional item to the ListBox control, and the control also offers a "Sort" function, so you can alphabetically sort the items you insert. The feature gives you the ability to dynamically add items to the control as the user sends feedback from your forms.
Instructions
-
-
1
Open the Visual Studio software from your Windows program menu. Open the Web project you want to edit and open the source code file for your Web form that contains the ListBox.
-
2
Create the string variables you want to use to fill the ListBox. The following code creates two string variables for the ListBox:
string item1 = "Choice 1";
string item2 = "Choice 2"; -
-
3
Add the values to the ListBox. The following code appends the two string variables to the choices in the ListBox control:
listbox1.Items.Add(item1);
listbox1.Items.Add(item2); -
4
Sort the appended values to alphabetically display the new values. Alphabetically displaying values makes it easier for users to find a specific value in the control, especially if you have several options to choose from. The following code sorts the ListBox:
listbox1.Sorted = true;
-
1