Reflection : TypeConverter for propertygrid

P

Paul Talbot

Hi,

I'm after help using reflection with the propertygrid. I am creating
a dynamic class and putting it into a propertygrid. For simple
textboxes, static content dropdowns and datetime controls it is fairly
simple. However I need a dynamic dropdown list.

I have an object that contains a list of departments. I want to add
this to a dropdown list within the propertygrid.

I know I need to use a typeconverter and this bit was tiresome but
achievable. Here's some code:

public class CCTypeConverter :StringConverter
{
private myItemCollection myValues = null;

public myItemCollection MyValues
{
get {return myValues;}
set {myValues = value;}
}
}

This is the top part of the StringConverter. I have the standard
overrides for each of the section I need and using a static object
(myItemCollection) I am able to populate it.

Here is the TypeConverterAttribute that I am using to get the static
version to work.

ConstructorInfo ciTypeConverter =
typeof(TypeConverterAttribute).GetConstructor(new Type[]
{typeof(System.Type)});

CustomAttributeBuilder cab = new
CustomAttributeBuilder(ciTypeConverter, new object[]
{typeof(CCTypeConverter)});

pb.SetCustomAttribute(cab);

This works perfectly. However I need to make it dynamic. There are
PropertyInfo[] and Object[] parameters that can be added to the
CustomAttributeBuilder, however I can't seem to get it to work, it
either returns null value not valid, or an error that could be one of
any 4 different errors.

So, is it possible to create a dynamic dropdown??!?!?!?
 

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