Video Lectures‎ > ‎

List n Combo box


Use of List box n Combo box

When you want to request information from the user, you can create an interactive interface using Visual Basic. Creating a list box is useful in situations where you want to give the user a list that does not leave room for an unforeseen choice. These list boxes can either be preset in code or built "on the fly," displaying the choices in a box of any size, scrollable if necessary. List boxes can also allow the user to select more than one option at at time. Once the list box has been created and filled out, your code can determine which entry was chosen by the user and its numerical position on the list. List boxes can also be linked to read and write data to a field in a database.

Difficulty:
 
Easy

Instructions

  1. Create the List Box

    • 1

      Go to the "Toolbox" palette and select the "List Box" tool. You can find this tool by hovering your mouse over each tool and noting the yellow tags that pop up and identify the names of the different tools.

    • 2

      Double-click on the "List Box" tool once you've found it. This will create a list box, which you can then resize.

    • 3

      Drag the resizing handles to stretch or shrink the list box's size. If a list box isn't tall enough to show all its entries, it will be scrollable.

    • 4

      Click on the interior of the list box to drag the entire box to different page position.

    Name the List Box

    • 1

      Select the list box. Click on the resizing handles to make sure the box is selected.

    • 2

      Browse the "Properties" window. You want to find the "Name" property.

    • 3

      Name the text box by clicking in the column next to "Name," and typing in a single alphanumeric word. This is what you will use to find the list box in later code.

    • 4

      Use the standard conventions when naming the list box by beginning with "lst" and following it with a capitalized short word that describes the list box's function. If you plan to link the list box will to a database, consider naming it "lst" and the name of the field it will be linking to.

    Populate the List Box From a Database

    • 1

      Set the "Datasource" property to the name of a data control (created on your form previously), which should represent the database you are linking to. This property can be set by following the same process you used to set the "Name" property.

    • 2

      Set the "Datafield" property to the name of the specific field you want this list box to link to. This property can also be set by applying the same process used to set the "Name" property.

    Populate the List Box From a List

    • 1

      Populate the "List" property by setting it to a string of alphanumeric values and typing CTRL-ENTER between each pair of values. These will be listed as options in the list box.

    • 2

      Populate the "Text" property by setting it to a string of alphanumeric values that you want the list box to display when the form is first viewed.



Reference: http://www.ehow.com/how_2056378_create-list-box-visual-basic.html

Comments