Hiding a row in a PropertyGrid

G

Guest

Is it possible to hide a row within a PropertyGrid based upon the boolean
value of another row within the PropertyGrid? I am using VS2005 with .NET
Frameworks 2.0.
 
J

Jeffrey Tan[MSFT]

Hi Steve,

This is not a trivial task. PropertyGrid exposes no interfaces to
manipulate its UI by removing/adding rows. Normally, PropertyGrid will use
Reflection to query the type/value on the SelectedObject and display one
property for a row. There is no easy way to tell PropertyGrid not to
display any row or add one row. PropertyGrid is not designed with this
function.

If you really want to achieve this task, one workaround is hooking into the
Reflection process of PropertyGrid during querying the object types/values.
Before PropertyGrid queries the properties, it will first query if the
object implement ICustomTypeDescriptor interface. So we can use this
interface as a hook to dynamically add/remove properties.
The codeproject article below demonstrates this technology:
"Add (Remove) Items to (from) PropertyGrid at Runtime"
http://www.codeproject.com/cs/miscctrl/Dynamic_Propertygrid.asp

Note: this technology needs the modification to the selected object instead
of the PropertyGrid class.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Marc Gravell

Actually - I seem to recall that you can do this by adding a custom
property-tab and simply tweaking the PropertyDescriptorCollection;
various examples on the net... removing is simpler... to add you need
to create your own PropertyDescriptor. Plenty of examples of that
also.

Marc
 

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