_EXTENDING MFC_ by Stefan Hoenig and Scot Wingo Listing One void CGXGridCore::ComposeStyleRowCol(ROWCOL nRow, ROWCOL nCol, CGXStyle*pStyle) { //Copy the cell style first GetStyleRowCol(nRow, nCol, *pStyle, secCopy); //Apply the row style next GetStyleRowCol(nRow,0,*pStyle,secApply); //Apply the colum style GetStyleRowCol(0,nCol,*pStyle,secApply); //Finally inherit any base styles pStyle->LoadBaseStyle(GetStylesMap()); } Listing Two BOOL CDBaseBrowserView::GetStyleRowCol(int nRow, int, nCol, SECStyle& style, SEC_OPERATION op) { if (nRow == 0) { // Column style style.SetStyle(GetField(nCol)->name); //Get column name from DB return TRUE; } //Advance row in DB (row = record) if (GetDocument()->m_dbfile.Seek(nRecord -1){ //Row headings if (nCol == 0){ char sz[20]; wsprintf(sz,"%5lu%c",nRow, GetDocument()->m_dbfile.IsDeleted() ? '*' : ' '); style.SetValue(sz); return TRUE; } //If we get here, we're looking up a cell. CSting s; CField * fld = GetField(nCol); //Get cell data and store along with max length GetDocument->m_dbFile.GetValue(GetFieldId(nCol),s);style.SetValue(s); style.SetMaxLength(fld->len); // Now set up the cell appearance based on field typeswitch(fld->type){ case 'N' : style.SetBaseStyle(SEC_NUMERIC); break; case 'C' : style.SetBaseStyle(SEC_TEXT); break; case 'D' : style.SetBaseStyle(SEC_DATE); break; case 'L' : style.SetBaseStyle(SEC_CURRENCY); break; // a sidenote: // this is also a good example for using base styles. The user can // change the appearance of all numeric, text, date and currency fields // at run time with the SECStyleSheet described above. // In OnInitialUpdate base styles are typicaly initialized // programmaticaly as for example: // BaseStyle(SEC_NUMERIC) // .SetHorizontalAlignment(DT_LEFT) // .SetFont(SECFont().SetBold(TRUE)); } return TRUE; } return FALSE; //At end of DB }