<< Return to Main Index

< Return to Class Index

CGXGridCore::SetStyleRange

virtual BOOL SetStyleRange(const CGXRange& range, const CGXStyle* pStyle, GXModifyType mt, int nType = 0, const CObArray* pCellsArray = NULL, UINT flags = GX_UPDATENOW, GXCmdType ctCmd = gxDo);

BOOL SetStyleRange(const CGXRange& range, const CGXStyle& style, GXModifyType mt = gxOverride, int nType = 0, UINT flags = GX_UPDATENOW);

range

A reference to a range-object specifying the cells to be changed. A range can be a range of cells, a range of rows, a range of columns or the whole table. (See the CGXRange class.)

pStyle

A pointer to a style-object which should be applied to the cells. This pointer can be NULL if pCellsArray is not NULL.

mt

Modify-Type: gxOverride, gxApplyNew, gxCopy or gxExclude (see the CGXStyle::ChangeStyle). If you want to remove style objects, you should pass gxRemove to mt and NULL to pStyle.

nType

A value greater than 0 can be used by yourself

pCellsArray

An optional pointer to an array-object with the cell contents. The size of the array must be range.GetWidth( )*range.GetHeight( ) cells. If pCellsArray is NULL, pStyle must not be NULL.

flags

Specifies the update technique. See UpdateStyleRange for more information.

ctCmd

Specifies if the executed command is undone (gxUndo), redone (gxRedo), executed the first time (gxDo) or rolled back (gxRollback).

style

A reference to a style-object which should be applied to the cells.

Return Value

TRUE if the command has been successfully executed; it is FALSE if the command failed or if the 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

Overridable command for applying cell formattings to the specified range of cells.

There are two prototypes for this command:

Cell formattings are stored with a call to CGXControl::StoreStyle for each cell. The display is updated with UpdateStyleRange.

If you want to hook into storing the cells for certain cell types you should override the control’s StoreStyle method. The default implementation of StoreStyle simply calls CGXGridCore::StoreStyleRowCol. For example, the StoreStyle implementation of the RTF Control will convert style settings like Bold, or Right Aligned, into RTF statements and store these RTF statements in the style value before it calls CGXGridCore::StoreStyleRowCol.

If the range is not a range of cells but a range of rows, columns or the whole table, StoreStyleRowCol is called with nType set to -1. See StoreStyleRowCol and GetStyleRowCol for the usage of nType.

If you want to remove style objects, you should pass gxRemove to mt and NULL to pStyle.

The command generates a CGXSetStyleRangeCmd-object with undo-information.

The user can abort the operation by pressing ESC.

If you only want to change the value and no other cell formattings, you should call SetValueRange.

Note

If you make a series of subsequent calls to SetStyleRange (e.g., when filling a grid), you should first call LockUpdate(TRUE) to prevent updating the grid each time SetStyleRange is called. Updating the grid each time requires computing window coordinates, invalidating the area and redrawing the cells (and will slow down performance substantially). After applying the styles to the cells, you should call LockUpdate(FALSE) and redraw the cells with RedrawRowCol or Redraw (see the description of LockUpdate for further details).

Example 4 illustrates how to use LockUpdate.

Example

These examples illustrate the usage of the SetStyleRange method:

Example 1 sets the value for a cell.

   SetStyleRange(CGXRange(nRow, nCol), CGXStyle( ).SetValue("1"));
   SetStyleRange(CGXRange(nRow, nCol+1), "2");      // short cut

Example 2 sets the font for a range of cells Bold.

   SetStyleRange(CGXRange(1, 1, 20, 1), CGXStyle( )
      .SetFont(CGXFont( ).SetBold(TRUE)) );

Example 3 applies several attributes for a range of rows.

   SetStyleRange(CGXRange( ).SetRows(3, 5), CGXStyle( )
         .SetFont(CGXFont( ).SetBold(TRUE))
        .SetVerticalAlignment(DT_VCENTER)
         .SetControl(GX_IDS_CTRL_COMBOBOX)
         .SetChoiceList("one\r\ntwo\r\nthree\r\nfour\r\nfive\r\n")
          .SetTextColor(RGB(255, 0, 0)
      );

Example 4 illustrates how to do a series of SetStyleRange commands.

   CGXStyle style;
   BOOL bLockOld = LockUpdate(TRUE);
   for (ROWCOL nCol = 1; nCol < 10; nCol++)
   {
      for (ROWCOL nRow = 1; nRow < 10; nRow++)
      {
         SetStyleRange(CGXRange(nRow, nCol),
            style.SetValue(nCol*10+nRow));
      }
   }
   LockUpdate(bLockOld);
   RedrawRowCol(1, 1, 10, 10);

Example 5: only the value will be copied, all other attributes will be reset.

   SetStyleRange(
      CGXRange(1, 1, 5, 5),
      CGXStyle( ).SetValue("xxx"),
      gxCopy);

Example 6: the interior and the font attribute will be reset, so these attributes will be filled up with the default background color and font when drawing.

   SetStyleRange(
      CGXRange(1, 1, 5, 5),
      CGXStyle( )
         .SetIncludeInterior(TRUE)
         .SetIncludeFont(TRUE),
      gxRemove);

Example 7: the interior and the font attribute will be applied to the cell only if they have not yet been initialized for the cells.

   SetStyleRange(
      CGXRange(1, 1, 5, 5),
      CGXStyle( )
         .SetInterior(RGB(255,255,255))
         .SetFont(CGXFont( ).SetBold(TRUE)),
      gxApplyNew);

See Also

CGXControl::StoreStyle CGXGridCore::SetValueRange CGXGridCore::StoreStyleRowCol CGXGridCore::GetStyleRowCol CGXGridCore::UpdateStyleRange CGXGridCore::LockUpdate CGXRange CGXStyle::ChangeStyle

CGXGridCore

Class Overview | Class Members