Hi, Guys,
I have been trying to validate and update data back to the original objects from a CMFCPropertyGridCtrl derived class CMFCPropList. But in the override of ValidateItemData function, the values obtain from CMFCPropertyGridProperty are always the original (not the edited) values except for combo box selection items. I searched the MSDN and can not find any other functions like GetItemText() etc. for getting the edited value. I could not obtain the edited values.
To update data back to the original objects, I tried to override the OnPropertyChanged(pProp) function, but in debugging, the program never run into the function no matter how the proerties was changed. I also tried to use PreTranslateMessage(msg) of the parent window to catch theAFX_WM_PROPERTY_CHANGED message, but it was also never sent no matter how the properties was changed.
Could anybody give me some clue as how to validate and update data from a property grid control. Any suggestions, tips and help are welcome and greatly appreciated.
Answer1:
I realise this is an old post and you may already have a solution, but having just discovered a method of doing this myself I thought it mighthelp others struggling with this aspect of the feature pack. The following example should provide sufficent code to get you started.
Note that the example assumes theproperties grid is embedded in aderived CDockablePane called CMyProperties. Also note that eachgrid and each item in the grid must be givenanunique ID upon creation. However,do remember to keep all yourcontrol IDs consistent with any existing controls. E.g., if you have a toolbar button that changes the same property, use the same control ID for both. Similarly with menu options and any other dialog controls.
// MyProperties.h
class CMyProperties : public CDockablePane
{
private:
DECLARE_DYNCREATE( CMyProperties )
protected:
DECLARE_MESSAGE_MAP()
afx_msg LRESULT OnPropertyChanged( __in WPARAM wparam, __in LPARAM lparam );
public:
// Otherclass members...
}
// MyProperties.cpp
BEGIN_MESSAGE_MAP( CMyProperties, CDockablePane )
ON_REGISTERED_MESSAGE( AFX_WM_PROPERTY_CHANGED, OnPropertyChanged )
END_MESSAGE_MAP()
LRESULT CMyProperties::OnPropertyChanged(
__in WPARAM wparam,
__in LPARAM lparam )
{
// Parameters:
// [in] wparam: the control ID of the CMFCPropertyGridCtrl that changed.
// [in] lparam: pointer to the CMFCPropertyGridProperty that changed.
// Return value:
// Not used.
// Cast the lparam to a property.
CMFCPropertyGridProperty * pProperty = ( CMFCPropertyGridProperty * ) lparam;
// At this point you could simply pass pProperty to the appropriate object
// and let it handle its owndata validation. However, the wparam can be used
// togive additional context to the property. For example, if you have two
// different class of object in your application, it makes sense to have two
// seaprateproperty grid controls (one for each object). The following switch
// deals with this scenario.
// Determine which property grid waschanged (wparam is the control ID).
switch( wparam )
{
case( ID_PROPCTRL_CLASS1 ):
// Note: For consistency, store all your control IDs in resource.h.
// Pass the appropriate control ID to the CMFCPropertyGridCtrl during
// creation. Here we've used ID_PROPCTRL_CLASS1 to show that this control
// relates to all the properties ofobjects of type CClass1.
// At this point we can simply pass pProperty to the appropriate CClass1
// object and let it handle its own data validation. The following code
// should therefore be placed in an appropriate CClass1 method such as
// pMyClass1->UpdateProperty( pProperty ). I've kept it here to keep this
// example as simple as possible.
// Determine which property was changed.
switch( pProperty->GetData() )
{
case( ID_CLASS1_PROP1 ):
// Note: For consistency, store all your control IDs in resource.h.
// Pass the appropriate control ID to the CMFCPropertyGridProperty during
// creation (data member). Here we've used ID_CLASS1_PROP1 to show that
// this property relates to class CClass1 member value m_Prop1. Since the
// object itself should deal with pProperty, you could use this data to
// assert when an inappropriate pProperty is passed.
// Get the property's current value.
COleVariant v = pProperty->GetValue();
// The object itself should cast the data to an approriate type (if required),
//validate the data and set the member via a set accessor method. The object's
// set accessor method should, in turn, notify all relevant controls that its
// member has been updated. Of course, all controls and the set accessor itself
// should have equality guards to prevent infinite loops.
break;
// Add 1 case per additional property control ID.
}
break;
// Add 1 case per additional property grid control ID.
}
// Note: the return value is not used.
return( 0 );
}
分享到:
相关推荐
jquery表单验证框架:jquery.validate.zip 附:中文API 文档
Module 8: Introduction to Data Analysis [removed]DAX)This module describes how to use DAX to create measures and calculated columns in a tabular data model.Lessons DAX Fundamentals Using DAX to ...
How to access and update part of the page using code. How to use JavaScript to communicate with the server and retrieve data. How to use JavaScript to for form validation and user feedback. How to use...
How to extract just the information you want from imported data, and manipulate it and format it the way you want Export your results to other programs or share with others in the cloud Organize, ...
The Schematron is a simple and powerful ...and checks.Schematron validation rules allow the author to specify a helpful error message which will be provided to the user if an error is encountered.
jQuery Validate 插件为表单提供了强大的验证功能,让客户端表单验证变得更简单,同时提供了大量的定制选项,满足应用程序各种需求。该插件捆绑了一套有用的验证方法,包括 URL 和电子邮件验证,同时提供了一个用来...
How to access and update part of the page using code. How to use JavaScript to communicate with the server and retrieve data. How to use JavaScript to for form validation and user feedback. How to use...
数据--验证--货币 Perl 模块验证字符串是否是正确的货币
H265(HEVC)格式解析
jquery.validate.js * * jQuery validation plug-in 1.7 * * http://bassistance.de/jquery-plugins/jquery-plugin-validation/ * http://docs.jquery.com/Plugins/Validation * * Copyright (c) 2006 - 2008...
解决普元EOS报错:edu.yale.its.tp.cas.client.IContextInit 下载后需jar到lib里面且单击右键在属性一栏的弹出框内添加该jar包即可解决爆粗
jquery-验证 jquery-validate 插件 安装 使用安装: $ component install virtru-components/jquery-validate 应用程序接口 执照 麻省理工学院
* How to extract just the information you want from imported data, and manipulate it and format it the way you want * Export your results to other programs or share with others in the cloud * ...
官方离线安装包,亲测可用
You can use Clojure spec to validate data, destructure data, explain invalid data, and generate large numbers of tests to verify the correctness of your code. With this book, you'll learn how to ...
Chapter 6, Fetching Data with Relay, explains how to effectively use Relay to query and fetch application data, and how to make it work with the application router. Chapter 7, Implementing Routing and...
Begin by understanding how to think computationally: to formulate a computational problem and recognize patterns and ways to validate it. Then jump ahead past the abstractions and conceptual work into...
• Explore how to use arrays, functions, and objects • Build and validate web forms • Work with databases and session management • Access APIs to interact with web services and other websites • ...
This Learning Path is for engineers and scientists who are familiar with Scala and want to learn how to create, validate, and apply machine learning algorithms. It will also benefit software ...