Columns, ColumnCount

These properties provide access to the columns in a grid. ColumnCount tells how many there are and Columns lets you actually touch the individual columns.ColumnCount also applies to combo boxes and list boxes, where it tells how many columns are displayed in the list or combo, but lists and combos don't have a matching Columns collection. (Use the List or ListItem collection instead.)

Usage

colColumn = grdGrid.Columns( nColumnNumber )
oObject.ColumnCount = nNumberOfColumns
nNumberOfColumns = oObject.ColumnCount
Lists and combos with a RowSourceType of 8-Structure sort of ignore the setting of ColumnCount because there's only one column's worth of information to display. They show the structure data in the first column and leave any other columns empty.

On the other hand, lists and combos with a RowSourceType of 7-Files should ignore ColumnCount and don't. With ColumnCount more than 1, you end up with multiple, identical columns. Be sure to set ColumnCount to 1 or the default, 0, if you use this RowSourceType. (Of course, there are better ways to let the user choose a file, including the Common Dialogs control, so we sure don't plan to use a lot of lists and combos with RowSourceType = 7.)


The default of 0 for combos and list boxes seems to be the same as specifying 1. For grids, the default of -1 is smart—it includes all fields of the table.As in FoxPro 2.x, getting columns in a multi-column list box or combo box to line up isn't automatic. However, it's much easier in Visual FoxPro. Set the ColumnWidths property appropriately.The Columns collection lets you access the columns of a grid without knowing their names. Be aware that the order in Columns is creation order, not the display order reflected by the ColumnOrder property.

Example

* Set up a multi-column list box. Assume we're in the 
* Init of the list.
This.ColumnCount = 3
This.ColumnWidths = "100,100,100"
This.RowSourceType = 2  && Alias
This.RowSource = "Customer"

See Also

ColumnOrder, ColumnWidths, List Property, ListItem, RowSource, RowSourceType


Back to Table of Contents

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