The row and column count can be changed at run time using the following APIs:
CGXGridCore::SetColCount()
Specifies the number of columns in the grid. If this number is greater than the current number of columns, new columns will be added to the right-hand side of the grid. If the new count is less the current count, the extra columns will be removed from the right-hand side of the grid.
CGXGridCore::SetRowCount()
Specifies the number of rows in the grid. If this number is greater than the current number of rows, new rows will be added to the bottom of the grid. If the new count is less the current count, the extra rows will be removed from the bottom of the grid.
CGXGridCore::InsertCols()
Inserts columns before a specified anchor column.
InsertCols(8, 5); // Insert 5 columns before column 8 |
To add columns at the bottom of the grid, use the current column count + 1 for the column ID in the above call.
// Add 3 columns to right-hand side of grid InsertCols(GetColCount() + 1, 3); |
CGXGridCore::InsertRows()
Inserts rows before a specified anchor row.
InsertRows(2, 4); // Insert 4 rows before row 2 |
To add rows to the bottom of the grid, use the current row count + 1 for the row ID in the above call.
// Add 2 rows to bottom of grid InsertRows(GetRowCount() + 1, 2); |
CGXGridCore::RemoveCols()
Removes the specified range of columns.
RemoveCols(1, 4); // Remove columns 1 through 4 RemoveCols(6, 6); // Remove column 6 |
CGXGridCore::RemoveRows()
Removes the specified range of rows.
RemoveRows(5, 10); // Remove rows 5 through 10 RemoveRows(3, 3); // Remove row 3 |
Columns and rows may be sized programmatically using CGXGridCore::SetColWidth() or CGXGridCore::SetRowHeight().
The end user can resize a column or row by dragging the grid line separating two headers. The column to the left or the row above the grid line being dragged is resized. You can change the behavior for end user resizing using:
CGXGridParam::EnableTrackColWidth()
Specifies how columns can be resized.
CGXGridParam::EnableTrackRowHeight()
Specifies how rows can be resized.
Or turn user resizing off by calling
CGXGridParam::EnableTrackColWidth(FALSE) |
or
CGXGridParam::EnableTrackRowHeight(FALSE). |
The end user can also size a column or row by double-clicking the adjacent grid line. Again, the column to the left or the row above will be resized. Double-clicking the grid line resets the column or row to the default size. The programmer can specify the default size using:
CGXGridCore::SetDefaultColWidth()
Specifies the default column width.
CGXGridCore::SetDefaultRowHeight()
Specifies the default row height.
Hidden columns have zero width. Hidden rows have zero height. The programmer can hide a column by calling CGXGridCore::HideCols()or hide a row by calling CGXGridCore::HideRows().
Bit visibility flags indicating which columns or rows are hidden are set in the grid object. Visibility flags are stored with a call to StoreHideRow() for each row or StoreHideCol() for each column. The display is updated with UpdateChangedRowHeights() or UpdateChangedColWidths().
CGXGridCore::HideCols()
An overridable command for specifying the visible-flag for specific columns. This function can also be used to unhide a column.
CGXGridCore::HideRows()
An overridable command for specifying the visible-flag for specific rows. This function can also be used to unhide a row.
The end user can hide a column or row by resizing the column or row to zero. (User resizing of rows and columns is discussed in Section 5.4.2.2.) Users can unhide hidden columns and rows by double-clicking the grid line where columns or rows are hidden. For example, if column 3 is hidden, the end user could double-click the grid line between the column 2 header and the column 4 header. This will cause column 3 to be resized to the default size. Users can also resize the column or row (using the special cursors shown in Figure 43 and Figure 44) until the column or row is restored.
To prevent users from hiding columns, override CGXGridCore::GetColWidth() as in the following code:
int CMyGrid::GetColWidth(ROWCOL nCol) { int nRet = CBaseGrid::GetColWidth(nCol); // Check if stored col width is less than min col width if (nRet < MIN_COL_WIDTH) { nRet = MIN_COL_WIDTH; } return nRet; } |
With the same logic, you can use GetRowHeight() to prevent users from hiding rows.
To prevent the user from resizing a hidden row, override OnTrackRowHeight(). Check for IsRowHidden()==TRUE and return FALSE when this is the case.
Frozen columns are columns that will never scroll out of the window; they are always fixed at the left side of the grid. Frozen rows are rows that will never scroll out of the window; they are always fixed at the top of the grid.
CGXGridCore::SetFrozenCols()
An overridable command for specifying the number of frozen columns and columns to be used as row headers. Row headers are columns that will be used to display titles for rows. They typically have a 3D-look.
CGXGridCore::GetFrozenCols()
An overridable method that returns the number of frozen columns stored in the parameter-object.
CGXGridCore::StoreFrozenCols()
An overridable method that stores the number of frozen columns and columns to be used as row headers to the corresponding attribute of the parameter-object.
You can override this method if you want to maintain the data in your own classes. The library accesses the data through GetFrozenCols() and GetHeaderCols().
CGXGridCore::UpdateFrozenCols()
An overridable method that updates the window display after freezing columns. The method simply calls Redraw().
The method creates the following hint:
CGXGridHint hint(gxHintUpdateFrozenCols, m_nViewID); hint.nCol1 = nOldFrozenCols; hint.nCol2 = nOldHeaderCols; hint.flags = flags; |
You can override this method if you need to change the hint.
CGXGridCore::SetFrozenRows()
An overridable command for specifying the number of frozen rows and rows to be used as column headers. Column headers are rows that will be used to display titles for columns. They typically have a 3D-look.
Numbering begins with zero. This means that if you set nFrozenRows = 0 and nHeaderRows = 0 there will still be one column header.
If you want to hide the first column header, you should call HideRows(0,0).
This example shows you how to use two rows for column headers:
// use 1 extra column as header ( + standard header at row 0) SetFrozenRows(1, 1); // Don't draw column headers pressed when moving current cell GetParam( )->GetProperties( )->SetMarkColHeader(FALSE); // Some column headers shall span over several columns SetCoveredCellsRowCol(0,2,0,4); // This looks like this: // |------|----------------|-----|-----| // | A | Group of Cols | E | F | // | | 1 | 2 | 3 | | | // |------|----------------|-----|-----| |
CGXGridCore::GetFrozenRows()
An overridable method that returns the number of frozen rows stored in the parameter-object.
CGXGridCore::StoreFrozenRows()
An overridable method that stores the number of frozen rows and rows to be used for column headers to the corresponding attribute of the parameter-object. The library accesses the data through GetFrozenRows() and GetHeaderRows().
You can override this method if you want to maintain the data in your own classes.
CGXGridCore::UpdateFrozenRows()
An overridable method that updates the display window after freezing rows. The method simply calls Redraw().
UpdateFrozenRows() creates the following hint:
CGXGridHint hint(gxHintUpdateFrozenRows, m_nViewID); hint.nRow1 = nOldFrozenRows; hint.nRow2 = nOldHeaderRows; hint.flags = flags; |
You can override this method if you need to change the hint.
Copyright © Rogue Wave Software, Inc. All Rights Reserved.
The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.