CString CMFCPropertyGridProperty::FormatProperty()
{
ASSERT_VALID(this);
ASSERT_VALID(m_pWndList);
COleVariant& var = m_varValue;
CString strVal;
if (m_bIsValueList)
{
for (POSITION pos = m_lstSubItems.GetHeadPosition(); pos != NULL;)
{
CMFCPropertyGridProperty* pProp = m_lstSubItems.GetNext(pos);
ASSERT_VALID(pProp);
strVal += pProp->FormatProperty();
if (pos != NULL)
{
strVal += m_pWndList->m_cListDelimeter;
strVal += _T(' ');
}
}
return strVal;
}
switch (var.vt)
{
case VT_BSTR:
strVal = var.bstrVal;
break;
case VT_I2:
strVal.Format(m_strFormatShort, (short)var.iVal);
break;
case VT_I4:
case VT_INT:
strVal.Format(m_strFormatLong, (long)var.lVal);
break;
case VT_UI1:
if ((BYTE)var.bVal != 0)
{
strVal.Format(m_strFormatChar, (TCHAR)(BYTE)var.bVal);
}
break;
case VT_UI2:
strVal.Format( m_strFormatUShort, var.uiVal);
break;
case VT_UINT:
case VT_UI4:
strVal.Format(m_strFormatULong, var.ulVal);
break;
case VT_R4:
strVal.Format(m_strFormatFloat, (float)var.fltVal);
break;
case VT_R8:
strVal.Format(m_strFormatDouble, (double)var.dblVal);
break;
case VT_BOOL:
strVal = var.boolVal == VARIANT_TRUE ? m_pWndList->m_strTrue : m_pWndList->m_strFalse;
break;
default:
// Unsupported type
strVal = _T("*** error ***");
}
return strVal;
}
代码如上面所示,如果直接使用COleVariant(COleDateTime.v_dt),显示的将是datetime 的数字形式