CGXControl::ConvertControlTextToValue

virtual BOOL ConvertControlTextToValue(CString& str, ROWCOL nRow, ROWCOL nCol, const CGXStyle* pOldStyle);

str

A reference to a string that is both used as input text and result. When you call ConvertControlTextToValue you should assign the display text to this string. ConvertControlTextToValue will convert this string and store the result back into this string.

nRow

Specifies the row id of the cell.

nCol

Specifies the column id of the cell.

nFlags

Specifies the update technique. See UpdateStyleRange for more information.

pOldStyle

An optional pointer to an existing style object for the cell. ConvertControlTextToValue can use this object to determine information about the cell (e.g., input mask or read-only state) without having to gather the style information from the grid.

Return Value

TRUE if the text could be converted; FALSE if the text is invalid.

Remarks

This method converts the display text into the value that should be stored in the grid. You might add validation into this routine and also adjust the text before it gets stored in the grid (e.g., remove literals like the ‘$’ or ‘/’ from currency or date values). ConvertControlTextToValue will be called from SetControlText.

ConvertControlTextToValue will be called from SetControlText when you paste text from CF_TEXT clipboard format into the grid or load data from a text file. You should use this function as a hook for adjusting the data.

CGXMaskControl has a special override of ConvertControlTextToValue and will remove any literals from the value before SetControlText stores the value via SetValueRange into the grid. CGXRichEditCtrl has overridden this method, too, and converts the unformatted text into an RTF string. CGXComboBoxWnd has a special mode where it searches the text in an associated choice list and only stores an index as value in the grid.

Example

This example demonstrates how to generate the date information without any formatting from a display string and store it in the grid.

// ConvertControlTextToValue
//
// Convert the text as is it displayed in the cell to the value
// which should be stored as value in the grid.
//
// str can be for example "01/01/91"
// The resulting text will the be "19910101" (as stored in dbase file)
//
// This function is typically called when you paste CF_TEXT data from
// clipboard.
BOOL CDbfDateControl::ConvertControlTextToValue(CString& str, ROWCOL nRow, ROWCOL nCol, const CGXStyle* pOldStyle)
{
   // Unused:
   nRow, nCol, pOldStyle;
   BOOL bSuccess = FALSE;
   // convert str into dbase date
   TIMESTAMP_STRUCT ts;
   if (GXParseDateTime(&ts, str, gxDEFAULT))
   {
      str.Format(_T("%04d%2d%2d"), ts.year, ts.month, ts.day);
      bSuccess = TRUE;
   }
   return bSuccess;
}

CGXControl

 Class Overview |  Class Members