Groups | Blog | Home
all groups > dotnet windows forms controls > may 2007 >

dotnet windows forms controls : PropertyGrid - an object instead of a TypeConverter typeof()?



David Thielen
5/26/2007 7:35:00 PM
Hi;

I have a property grid where I need to pass it an object with N properties
in it that are each an enumeration (but not an enum). These properties and
they enumerated values are read from a database - so we don't know beforehand
how many there will be and we do not know beforehand what their enumerated
values are.

All of the examples for handling something like this show creating a class
that implements TypeConverter and then passing that class. But we do not know
what the choices are and we do not know how many of these properties we will
have.

If this was done by passing an object that implements TypeConverter this
would be a piece of cake - is there a way to do that?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm

David Thielen
5/26/2007 7:59:00 PM
What we have is a list of values and an int for the present value. The list
of values is a 0-based array of strings. So if I use the actual value I will
get 0, 1, 2, etc. When I want "dave", "fred", etc...

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




[quoted text, click to view]
AlexS
5/26/2007 10:44:15 PM
If you set such object to grid.SelectedObject - what exactly you miss in the
final display? Do you miss any properties?


[quoted text, click to view]

AlexS
5/26/2007 11:18:16 PM
Then probably you'll be better off using DataGridView control, which allows
custom formatting of displayed values.

PropertyGrid shows properties as is. You can add another property to your
class, returning string for current int, so you will see both values - maybe
that'll help


[quoted text, click to view]

VisualHint
5/27/2007 5:41:57 AM
Hello David,

you will find a solution either with a TypeConverter or a custom
TypeDescriptor. First let me tell you that the PropertyGrid resource
list (see my signature) will give you a lot of pointers to handle
these classes.

Some of my customers had a similar question and I wrote a FAQ. It
allows to dynamically set the possible values and the underlying
integer identifiers in a combobox property. It is sometimes specific
to Smart PropertyGrid but you will be able to grab the main ideas from
it that you can apply to the Microsoft PropertyGrid. The link is:
http://www.visualhint.com/index.php/blog/post/how_to_setup_a_truly_dynamic_combobox_in_the_propertygrid/

Another thing: if you want to determine the current displayed values
for a property and the number of properties from inside your
converter, use the context variable passed to the converter's methods.
You will be able to access your target instance and request it the
properties loaded from the database and their values.

I hope this helps.

Best regards,

Nicolas Cadilhac @ VisualHint (http://www.visualhint.com)
Home of Smart FieldPackEditor.Net / DateTimePicker replacement
Home of Smart PropertyGrid for .Net and MFC
Microsoft PropertyGrid Resource List - http://www.propertygridresourcelist.com


[quoted text, click to view]

AlexS
5/27/2007 10:09:38 AM
Thanks for pointers


[quoted text, click to view]

v-lliu NO[at]SPAM online.microsoft.com
5/28/2007 12:00:00 AM
Hi Dave,

Sorry that I couldn't understand your question exactly.

[quoted text, click to view]
properties
in it that are each an enumeration (but not an enum).

Could you tell me what you mean by "but not an enum" in the above sentence?

[quoted text, click to view]
we don't know beforehand how many there will be and we do not know
beforehand what their enumerated values are.

Do you mean that the properties and enumerated values are created at run
time? If so, how do you add the properties to the object at run time?

Could you please explain what your question is exactly?

I look forward to your reply.

Sincerely,
Linda Liu
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.
David Thielen
5/28/2007 7:39:01 AM
VisualHint's post showed me how to do this.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




[quoted text, click to view]
David Thielen
5/28/2007 7:39:01 AM
perfect - thanks
--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




[quoted text, click to view]
AddThis Social Bookmark Button