The Columns property contains a collection of column objects for the specified grid.
object.columns(ColIndex) = [collection]
When a subfile is received from the IBM i, the recognition engine attempts to organize its data into columns. These columns are represented by the columns collection.
If columns are clearly identified in the subfile, then the ShowColumns property defaults to True and column separators are displayed in the GUI. When the recognition engine encounters ambiguities in column recognition, then the ShowColumns property defaults to False, columns are not displayed and the Columns Editor is disabled in Designer. Column information is still stored in the Columns collection however and it is possible to force the data into columns by setting the ShowColumns property to True, either in Designer, or via a script or macro. When column recognition is forced on, the recognition engine inserts blank cells, where necessary, in order to organize the data into logical columns and maintain grid headings.
When a data grid control has columns enabled, there may be a difference between the total number of identified columns, which can be returned by the App.ActiveForm.grid.Columns.Count
property, and the total number of columns displayed in the GUI. This is because the recognition engine hides certain columns that it identifies as non-data or 'padding' columns. By default, these columns have their Visible property set to False.
For this reason it is important to use the Columns.Count property to determine the total number of columns in a subfile before creating any code that references specific columns or contains looping structures. (Refer to the ColCounts collection topic for information on looping through cells in non-column grids).
If the ShowColumns property of a datagrid is set to False then any modifications you make to columns in the Columns collection editor will not be applied.
A datagrid's column properties can be set statically in Designer or dynamically at runtime via a macro or script.
To set column properties in Designer, you can either click on the expander () next to the Columns property in the property grid or select Show Columns Editor from the grid's right-click context menu.
The Datagrid column editor allows you to view, modify, add and re-order a grid's columns.
To modify column properties within a macro or script at runtime you must reference the column, either by its name or by its index in the Columns collection. For example:
App.ActiveForm.myGrid.Columns(2).Alignment = nlAlignRight;
App.ActiveForm.myGrid.ItemID.Alignment = nlAlignRight;
Refer to the Column object property for a list of available column properties.
To add or remove columns from a data grid control, use the Add and Remove buttons in the columns collection editor (then reposition the column as desired using the arrows) or use the InsertColumn, InsertColumnArray and DeleteColumn methods at runtime.
It is not possible to remove columns that have been generated from host subfiles. In order to hide these columns turn the Visible property to False.
Any given cell in a data grid control can be referenced in one of the following three ways:
datagrid.Cells(RowIndex, CellIndex)
datagrid.Rows(RowIndex).Cells(CellIndex)
datagrid.Columns(ColIndex).Cells(RowIndex)
The first two methods use the Cell Index within the specified row to reference the cell.
In some grids the total number of cells may vary from row to row therefore the same Cell Index on any two rows does not necessarily mean that these two cells are in the same column. When you need to ensure that the returned cell is within the specified column however use the syntax columns(ColIndex).Cells(RowIndex).
With grids bound to a data source, the number of cells in each row is consistent with the number of columns, so in this case, the column index and cell index will be the same.
ShowColumns property | Column object | Columns collection | DataGrid control
© 2004-2021 looksoftware. All rights reserved.