我一直在MFC中开发一个程序,该程序使用位于我的数据库中的一些数据填充PropertyGrid。 此PropertyGrid中的一个字段包含与人的年龄相关的数据。这是实施:
CMFCPropertyGridProperty * pProp = new CMFCPropertyGridProperty(_T("Age"), (variant_t)PropAge->GetNext(headAge), _T("This is a description"));
pProp->EnableSpinControl(TRUE, 0, 150);
pGroup->AddSubItem(pProp);
其中PropAge
是包含CList
的{{1}}。
这是我的问题:当我尝试修改它的值(使用SpinControl或键入其他值)时,新值不会以粗体显示。此外,当我使用方法age (integer) of each person's register
时,它返回false:
IsModified()
我使用调试器检查发生了什么,看到了一些非常有趣的东西:
http://img836.imageshack.us/img836/8256/c90j.jpg
(注意:void CPropertiesWnd::DoSomething()
{
CMFCPropertyGridProperty * PropSel;
PropSel = m_wndPropList.GetCurSel();
bool a = PropSel->GetSubItem(1)->IsModified(); //SubItem containing the Age data.
//Returns False when it's modified!
//It always returns 'false', even if
//there was made a modification.
}
表示当前值,m_VarValue
表示修改前的que值)
如您所见,变量m_VarValueOrig
和m_VarValue
之间存在类型差异。 (I4是什么意思?)
我还注意到这个项目还有其他子项目也处理数字,它们实际上显示了什么时候 做了一个修改。他们的实现是这样的:
m_VarValueOrig
这是什么' l'在0之后意味着什么?它与I4类型有关吗?
答案 0 :(得分:0)
解决!解决方案实际上非常简单:在创建指向新PropertyGridProperty的指针的第二个参数中不使用(variant_t)
,而应使用(long)
转换以正确检测对其的修改子项:
CMFCPropertyGridProperty * pProp = new CMFCPropertyGridProperty(_T("Age"), (long)PropAge->GetNext(headAge), _T("This is a description"));