Used to return the total number of identified columns in the datagrid.
There are some additional things to consider when using this property
with a DataGrid's Columns collection.
When a data grid control is generated from an IBM i subfile,
there is often a difference between the total number columns that the recognition engine "identifies" in the grid (which is returned by the <datagridControl>.Columns.Count
property), and the total number of columns that are displayed at runtime. This is because IBM i subfiles often contain columns that exist only to align the contents of the subfile. The Newlook
recognition engine will automatically hide these non-data columns at runtime. The columns exist, and are included in the grid's columns count, but their Visible property defaults to False. You can check a specific column's index in Inspector or by opening the grid's Column Editor in Designer.
It is also possible for individual rows in the data grid control to contain a different
number of cells. For this reason, if the total number of cells in a specific row is
required, then it is important that you use the syntax <datagridControl>.ColCount(<RowIndex>)
. This
is particular relevant when looping through all the cells in a grid.
There may also be a difference in the number of columns returned by
the Count property when the ShowColumns property is True compared
to when it is False. When ShowColumns is turned on the recognition
engine performs special processing to match column headings with their
associated columns, even if they do not begin at the same green screen
column location. The columns are adjusted so that both align. With ShowColumns
set to False there is no column adjustment performed. Every time the recognition
engine identifies a new cell in a row it will create a column. Headings
that are not aligned will create additional columns in the Columns collection.
Therefore it is not unusual to come across a subfile that will return
more columns with ShowColumns turned off than it will with ShowColumns
turned on.
The following JScript example returns the total number of identified rows and columns for the grid:
//Obtain maximum row and column count for the grid
var control = App.ActiveForm.MyGrid;
intGridColumnCount = control.Columns.Count;
intGridRowCount = control.RowCount;