ColumnWidths

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.

Usage

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.

Figure 1: ListBoxes without and with the ColumnWidths property set.

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.

In early versions of VFP 6, ColumnWidths doesn't work if the form's ScaleMode has been set to 3–Foxels. All columns get set to the width of the first column, whether you set this in the Property Sheet or in code. We generally think that using foxels is a bad idea, as the geometry of the form depends on a font that may not even be used, so you shouldn't run into this one very often. The problem was fixed in one of the VFP 6 service packs.


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.

Example

lstListBox.ColumnWidths = "40, 20, 60, 80"

See Also

ColumnCount, ComboBox, FontMetric(), ListBox, ScaleMode, TxtWidth()


Back to Table of Contents

Copyright © 2002-2018 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. Click for license .