Some questions about PropertyGrid control

G

Guest

Now I am developing a tool, just like VS.net Form Edition environment.
User can edit a component's properties by a PropertyGrid control.
Now I have some questions about this PropertyGrid control:
1. How to verify a property's validifity?
as you know, In VS.net, when we input a component name that is same with an
existed name in the propertygrid, an error message will pop up: "Invalid
property value".
Now, my question is, how to implement this verification?
Certainly, I can check every property's validifity by handling the event
PropertyValueChanged. But I think it is not so good, because there are so
many properties, and it is a little complicated about logic.
Could you give me a classical solution about this problem?

2. How to change readonly attribute of a property at run time?
As we know, if we want a property to be readonly, we can implement it by
adding an ReadonlyAttribute above the property. But how to changed it at run
time?
In some cases, a property's edition maybe make another property to be
readonly.
So how to create this relationship between properties.

I am a little comfused about propertyGrid control, Could you tell me a good
solution?
Any advice is appreciated.
Thank you.
 
G

Guest

micro_bug said:
1. How to verify a property's validifity?
as you know, In VS.net, when we input a component name that is same with an
existed name in the propertygrid, an error message will pop up: "Invalid
property value".
Did you try to throw an ArgumentException from the property set function ?
2. How to change readonly attribute of a property at run time?
I know one solution that is not really trivial: your class must implement
ICustomTypeDescriptor and you must also derive a new class from
PropertyDescriptor.
Put together you have full control on the behaviour of your object
properties.
Concerning your case, you would override the PropertyDescriptor.IsReadOnly
property.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top