CGXGridCore::ResizeColWidthsToFit
virtual BOOL ResizeColWidthsToFit(CGXRange range, BOOL bResizeCoveredCells = TRUE, UINT nFlags = GX_UPDATENOW);
range
Specifies the range of cells through which ResizeColWidthsToFit will loop to find the optimal width for the affected columns.
bResizeCoveredCells
TRUE if covered cells which span several columns shall be resized, FALSE if covered cells shall be ignored.
nFlags
Specifies the update technique:
- GX_UPDATENOW specifies to update the window after each column-width change.
- GX_INVALIDATE simply invalidates the window area to the right of the first column that is resized.
- GX_NOSHRINKSIZE specifies that the column-width should not become smaller. Columns shall only be enlarged.
Return Value
TRUE if command succeeded; FALSE if command failed or user aborted the operation.
If you do a series of commands, you should check the return value and abort your operation (or rollback the transaction) if the return value is FALSE.
Remarks
Call this command to automatically resize the column-widths for a given range of cells.
ResizeColWidthsToFit will loop through each cell in the range and call the associated control’s CalcSize method to determine the optimal width for the cell. For each column, ResizeColWidthsToFit calculates the maximal width from the individual cells.
If there is a covered cell and the specified range includes all columns spanned by the covered cell, and bResizeCoveredCells is TRUE, ResizeColWidthsToFit will resize the last column of the covered cell.
The user can abort the operation.
All SetColWidth commands are packed in a transaction (BeginTrans, CommitTrans block). Therefore, the user can undo all changes with one undo-command.
Control-Factory Specific ->
This method has been implemented using the abstraction mechanism as discussed in the chapter "Reducing the size of your application" in the user's guide. A call to the ImplementResizeToFit method from within the control factory class' InitializeGridComponents method will make the concrete implementation of this method available to your application.
If no concrete implementation is available this method returns FALSE. A warning will be displayed in the debug window.
END Control-Factory Specific
Example
The first example resizes columns 5 to 7.
ResizeColWidthsToFit(CGXRange( ).SetCols(5, 7));
The next example resizes the column of the current cell.
ROWCOL nRow, nCol;
if (GetCurrentCell(nRow, nCol))
ResizeColWidthsToFit(CGXRange(nRow, nCol));
See Also
CGXControl::CalcSize CGXGridCore::SetColWidth