CGXBrowserGrid::OnLoadCellStyle

virtual BOOL OnLoadCellStyle(ROWCOL nRow, ROWCOL nCol, CGXStyle& style, LPCTSTR pszExistingValue);?

nRow

Specifies the row id.

nCol

Specifies the column id.

style

A reference to the style-object where you should store the cell formatting.

pszExistingValue

A pointer to a string which contains the changed value for the cell. NULL if cell has not been changed.

Return Value

Nonzero if successful; otherwise 0.

Remarks

Called to load the value from data source or apply additional formatting at runtime. This method provides a better abstraction for loading data from data sources at record level. OnLoadCellStyle is called from GetStyleRowCol when needed.

Note: You should override this method to load the value from data source or apply additional formatting at runtime. If pszExistingValue is not NULL, it contains the already existing value of the current buffer. You should then only initialize specific formatting here, but not change the cell value. If pszExistingValue is NULL, you should load the value from your external data source.

Currently, pszExistingValue is not NULL when the value has been changed for the current record. In a future version pszExistingValue may also be not NULL if the value is cached somewhere.

When you override this method, be careful that you don't forget to call this base class version of the method.

Example

Typically, you override this method to retrieve data from your external data source and convert data from an internal format into displayable text for the cell, as for example in the DbfBrows sample:

BOOL CDbfBrowserView::OnLoadCellStyle(ROWCOL nRow, ROWCOL nCol, CGXStyle& style, LPCTSTR pszExistingValue)
{
   CGXBrowseParam* pBrowseData = GetBrowseParam();
   ASSERT(nRow <= LONG_MAX);
   if (nRow > 0 && nCol > 0)
   {
      long nRecord = GetRecordFromRow(nRow);
      if (GetDocument()->m_dbfile.Seek(nRecord))
      {
         // Cell value
         CField* fld = GetField(nCol);
         // Outline deleted records
         if ( GetDocument()->m_dbfile.IsDeleted() )
         {
            // load base style for deleted rows
            style.SetBaseStyle(GetDocument()->m_wStyleDeletedRows);
            style.LoadBaseStyle(*GetParam()->GetStylesMap());
         }
         if (pszExistingValue == NULL)
         {
            // Load value from dbase file if value has not been Existing
            CString s;
            GetDocument()->m_dbfile.GetValue(GetFieldFromCol(nCol), s);
            if (fld->type == 'D' && !s.IsEmpty())
            {
               // Convert date values to displayable text
               TIMESTAMP_STRUCT ts;
               memset(&ts, 0, sizeof(TIMESTAMP_STRUCT));
               if (s.GetLength() == 8)
               {
                  ts.day = _ttoi(s.Mid(6, 2));
                  ts.month = _ttoi(s.Mid(4, 2));
                  ts.year = _ttoi(s.Left(4));
                  GXFormatTimeStamp(s, &ts);
               }
            }
            else if (fld->type == 'N')
            {
               TCHAR szFormat[10], szValue[128];
               wsprintf(szFormat, _T("%%.%df"), fld->decimals);
                BOOL bIsDigit = !s.IsEmpty();       )
                  bIsDigit &= _istdigit(*p) || _istpunct(*p) || _istspace(*p);
               if (bIsDigit)
                  _stprintf(szValue, szFormat, _gxttof(s));
               else
                  _tcscpy(szValue, _T(""));
               s = szValue;
            }
            style.SetValue(s);
         }
         // Note on UNICODE/DBCS Support:
         // fld->type is a signed char even for this special modes
         switch (fld->type)
         {
         case 'N': style.SetBaseStyle(GetDocument()->m_wStyleNumeric);
                  style.SetMaxLength(fld->len);
                  break;
         case 'C': style.SetBaseStyle(GetDocument()->m_wStyleText);
                  style.SetMaxLength(fld->len);
                  break;
         case 'D': style.SetBaseStyle(GetDocument()->m_wStyleDate);
                  break;
         case 'L': style.SetBaseStyle(GetDocument()->m_wStyleLogical);
                  break;
         }
      }
      return TRUE;
   }
   // Unused:
   nRow, nCol, style, pszExistingValue;
   return FALSE;   // return TRUE if you have changed the style object!
}

See Also

CGXGridCore::GetStyleRowCol

CGXBrowserGrid

Class Overview |  Class Members