The ColumnWidths property allows you to specify the widths of each column in a ComboBox or ListBox to force the columns to line up, even when using proportional fonts.
lboListBox.ColumnWidths = cWidthsExpr
cWidthsExpr = lboListBox.ColumnWidths
By default, each row in a list box or combo box has a width based on the contents and the font in which it's rendered—a visual disaster, as shown in Figure 1. Adding the setting of ColumnWidths brings these rogue columns under control, as in the right-hand part of the figure.
Specify ColumnWidths as a character string containing a comma-separated list of the widths of each column, in the current ScaleMode of the form, as in the example shown below. To calculate these widths, consider using TXTWIDTH()
and FONTMETRIC()
to get the values you need.
The individual column widths may be separated by spaces for ease in reading, or packed tight if that is your preferred style—Visual FoxPro seems to read either with ease. If you want to leave your last column to take up as much space as it needs—say, for free-form text descriptions, just don't specify the last column width, and it will display all data in that column.
To hide a column, such as the one containing the primary key for the table shown, set its width to 0.
lstListBox.ColumnWidths = "40, 20, 60, 80"
ColumnCount, ComboBox, FontMetric(), ListBox, ScaleMode, TxtWidth()