Share via


Creating Multicolumn List Boxes

Although the default number of columns in a list box is one, a list box in Visual FoxPro can contain as many columns as you want. A multicolumn list box differs from a grid in that you select a row at a time in a multicolumn list box while you can select individual cells in a grid, and data in the list cannot be directly edited.

To display multiple columns in a list box

  1. Set the ColumnCount property to the number of desired columns.

  2. Set the ColumnWidths property. For example, if there are three columns in the list box, the following command would set the column widths to 10, 15, and 30, respectively:

    THISFORM.listbox.ColumnWidths = "10, 15, 30"
    
  3. Set the RowSourceType property to 6 - Fields.

  4. Set the RowSource property to the fields to be displayed in the columns.

    Note   For the columns to align correctly, you need to either set the ColumnWidths property or change the FontName property to a monospaced font. The FirstElement property of ListBoxes and ComboBoxes is not effective in multi-column lists.

When the RowSourceType of the list is set to 0 - None, you can use the AddListItem method to add items to a multicolumn list box. For example, the following code adds text to specific columns in a list box:

THISFORM.lst1.ColumnCount = 3
THISFORM.lst1.Columnwidths = "100,100,100"
THISFORM.lst1.AddListItem("row1 col1", 1,1)
THISFORM.lst1.AddListItem("row1 col2", 1,2)
THISFORM.lst1.AddListItem("row1 col3", 1,3)
THISFORM.lst1.AddListItem("row2 col2", 2,2)

See Also

Choosing the Type of Data for a List or Combo Box | Allowing Users to Select Multiple Items in a List Box | Using Controls | Allowing Users to Add Items to a List Box | Controls and Objects