<< Return to Main Index

< Return to Class Index

CGXControl::GetControlText

virtual BOOL GetControlText(CString& strResult, ROWCOL nRow, ROWCOL nCol, LPCTSTR pszRawValue, const CGXStyle& style);

strResult

A reference to a CString where the method stores the formatted text.

nRow

Specifies the row id of the cell.

nCol

Specifies the column id of the cell.

pszRawValue

An optional pointer to a null-terminated string with the plain value. If pszRawValue is NULL, the value will be read from the style object. If pszRawValue is not NULL, this null-terminated string will be converted.

style

A reference to the style object for the cell.

Return Value

Specifies whether the operation was successful. If it is non-zero, a strResult holds a valid string; if it is FALSE, no value has been copied to strResult.

Remarks

Converts the value from the style object into plain text and formats this text. GetControlText will be called before drawing the cell and also for copying the text to the clipboard.

The base class version of this method simply returns the value determined with style.GetValue().

If you want to display the cell in a special format (e.g., display Currency values, or dates), you should override this method and convert the plain value (specified either with pszRawValue or style.GetValue) into the specific format which should be displayed in the cell (see also the attached example).

Please note that this method also has a counterpart method called SetControlText. SetControlText lets you adjust the text before it stores the value in the grid. SetControlText will be called for each affected cell if you paste text from the clipboard into the grid.

CGXMaskControl has a special override of GetControlText and will return the text including literals as it is displayed in the cell. CGXRichEditCtrl has overridden this method too, and returns the unformatted text for the cell. CGXComboBoxWnd has a special mode whereby it returns the choice list entry based on an index stored in the value.

Example

This example demonstrates how to display a date string in the cell while the style only holds the date information without any formatting.

// GetControlText
//
// Convert the value that is stored in the style object into
// the text which should be displayed in the cell.
//
// Style text can be for example "19910101" (as stored in dbase file)
// The resulting text will be "01/01/91" (as displayed in cell)

BOOL CDbfDateControl::GetControlText(CString& strResult, ROWCOL nRow, ROWCOL nCol, LPCTSTR pszRawValue, const CGXStyle& style)
{
   CString sValue;

   if (pszRawValue)
      sValue = pszRawValue;
   else
      sValue = style.GetValueRef();

   TIMESTAMP_STRUCT ts;
   memset(&ts, 0, sizeof(TIMESTAMP_STRUCT));

   if (sValue.GetLength() == 8)
   {
      ts.day = _ttoi(sValue.Mid(6, 2));
      ts.month = _ttoi(sValue.Mid(4, 2));
      ts.year = _ttoi(sValue.Left(4));

      GXFormatTimeStamp(strResult, &ts);

      return TRUE;
   }

   return CGXEditControl::GetControlText(strResult, nRow, nCol, pszRawValue, style);
}

See Also

CGXControl::SetControlText CGXMaskControl CGXRichEditCtrl CGXComboBoxWnd

CGXControl

Class Overview | Class Members