<< Return to Main Index

< Return to Class Index

CGXGridCore::GetStyleRowCol

virtual BOOL GetStyleRowCol(ROWCOL nRow, ROWCOL nCol, CGXStyle& style, GXModifyType mt = gxCopy, int nType = 0);

nRow

Specifies the row id.

nCol

Specifies the column id.

style

A reference to a style-object to store the result.

mt

Modify-Type: gxOverride, gxApplyNew, gxCopy or gxExclude (see CGXStyle class).

nType

Specifies the type of information to be retrieved:

Return Value

TRUE when a style could be retrieved.

Remarks

Overridable method which retrieves the pure style for the specified cell not inheriting attributes from its base-styles. The base-class version of this method retrieves the cell style from the data-object (CGXData::GetStyleRowCol) maintained by the parameter-object and applies it to the style-object.

Override this method if you want to dynamically bind the grid to a C Library for database handling. The cell style should be applied to the style object. (See the example).

Note that nType is -1 to retrieve the base-style for the whole row, column or table. If nType is -1, either nRow or nCol is zero and mt is set to gxApplyNew. If both nRow and nCol are zero, the base-style for the table is retrieved.  mt set to gxApplyNew means that you should only change those attributes which are not yet included in style.

If nType is greater or equal to 0, the style which should be displayed in the grid is returned. The grid-component uses mt set to gxCopy. This means you can change the style without any restriction.

When using the formula engine and nType is equal to GX_VALUE_EXPRESSION the formula expression (if available) will be assigned to the style value. If nTyoe is 0 (GX_VALUE_TEXT) the evaluated cell value (the result) will be assigned to the cell value.

Note:

If you don't want to change your existing code (and you don't need formula support at all) you can disable assigning expressions to cells by calling

   GXGetAppData()->m_nExpressionValueType = GX_VALUE_TEXT

Example

This example illustrates how to use the grid as dbase-file viewer. In this sample we override GetStyleRowCol and do not call the base class version of GetStyleRowCol.

BOOL CDBaseBrowserView::GetStyleRowCol(ROWCOL nRow, ROWCOL nCol, CGXStyle& style, GXModifyType mt, int nType)
{
   if (mt == gxRemove) // not supported
      return FALSE;

   // Note: I do not distinguish between gxApplyNew, gxCopy and gxOverride

   ASSERT(nRow <= LONG_MAX);
   long nRecord = (long) nRow;

   if (nType == -1)
   {
      // here you can return the style for a complete row, column or table
      return FALSE;
   }
   else if (nRow == 0 && nCol == 0)
   {
      // style for the top-left button
      return FALSE;
   }
   else if (nRow == 0)
   {
      // Column headers
       style.SetValue(GetField(nCol)->name);
   }
   else if (GetDocument( )->m_dbfile.Seek(nRecord-1))
   {
      if (nCol == 0)
      {
         // Row headers
         TCHAR sz[20];
         wsprintf(sz, "%5lu%c", nRow, GetDocument( )->m_dbfile.IsDeleted( ) ? '*' : ' ');
         style.SetValue(sz);
      }
      else
      {
         // Cell value
         CString s;
         CField* fld = GetField(nCol);
         GetDocument( )->m_dbfile.GetValue(GetFieldId(nCol), s);

         style
            .SetValue(s)
            .SetMaxLength(fld->len);

         switch (fld->type)
         {
         case 'N':   style.SetBaseStyle(GetDocument( )->m_wStyleNumeric); break;
         case 'C':   style.SetBaseStyle(GetDocument( )->m_wStyleText); break;
         case 'D':   style.SetBaseStyle(GetDocument( )->m_wStyleDate); break;
         case 'L':   style.SetBaseStyle(GetDocument( )->m_wStyleLogical); break;
         }
      }
      return TRUE;
   }

   // unreferenced:
   mt;

   return FALSE;
}

The next sample shows you how you can outline cells depending on their value. The GetStyleRowCol override changes only the SetInterior( ) style of a cell, which can be one of

      gray : value not used (cell will be made read-only, another change)
 
      white : value is not yet set
 
      green : value is set, interacting values result in feasible set
 
      red : value is set, interacting values result in infeasible set
 

 All other properties of the cell remain unchanged. 

BOOL CSampleView::GetStyleRowCol(ROWCOL nRow, ROWCOL nCol, CGXStyle& style, GXModifyType mt, int nType)
 {
    CMyGridView::GetStyleRowCol(nRow, nCol, style, mt, nType);

 // Note: Do not distinguish between gxApplyNew, gxCopy and gxOverride

    if (nRow > 0 && nCol > 0 && nType == 0)
    {
       style.SetValue(GetDocument( )->GetCellValue(nRow, nCol);
    }

    CString s = style.GetValueRef( );

    if (!used)
       style.SetEnabled(FALSE).SetInterior(RGB(192,192,192));
    else if (s.IsEmpty( ))
       style.SetInterior(RGB(255,255,255));
    else if (valid s)
       syle.SetInterior(RGB(255,0,0));
    else
       style.SetInterior(RGB(0,255,0));

    return TRUE;
 }

See Also

CGXGridCore::ComposeStyleRowCol CGXGridCore::StoreStyleRowCol CGXData::GetStyleRowCol

CGXGridCore

Class Overview | Class Members