Problem adding SortedList<TKey, TValue> to PropertyGrid

Z

za

Hello,

I want to use the propertygrid control to add and delete items form a
SortedList<TKey, TValues>, but I can't get it to work. Have someone a clue
where to start and get it working with a propertygrid?

TIA,

Fred
 
J

Jeff Johnson

I want to use the propertygrid control to add and delete items form a
SortedList<TKey, TValues>, but I can't get it to work. Have someone a clue
where to start and get it working with a propertygrid?

More than likely you're going to have to use a special editor* to work with
the list, since the property grid won't by default break this collection out
into separate rows like it will with an object's properties. Using custom
editors isn't all that hard, but it requires a bit of research on the
subject. The granddaddy class is System.Drawing.Design.UITypeEditor, and
there are derived classes in System.ComponentModel.Design which may or may
not help you, like CollectionEditor. I have a feeling that won't work for
dictionaries, though (which SortedList basically is). You may be able to
find examples of custom editors on www.codeproject.com which can point you
in the right direction.



*More than likely one you'll have to write yourself.
 
Z

za

Jeff Johnson said:
More than likely you're going to have to use a special editor* to work
with the list, since the property grid won't by default break this
collection out into separate rows like it will with an object's
properties. Using custom editors isn't all that hard, but it requires a
bit of research on the subject. The granddaddy class is
System.Drawing.Design.UITypeEditor, and there are derived classes in
System.ComponentModel.Design which may or may not help you, like
CollectionEditor. I have a feeling that won't work for dictionaries,
though (which SortedList basically is). You may be able to find examples
of custom editors on www.codeproject.com which can point you in the right
direction.



*More than likely one you'll have to write yourself.
Hello Jeff,

I was afraid of writing the uitypeditor myself, the only thing I can't
figure out is how to do it. Example:

class Sample
{
public string Name { get; set; }

public string Description{ get; set; }
}

class Sample will be visible and editable in the propertygrid, how does the
propertygrid that the class has two properties?

Reg. Fred
 
J

Jeff Johnson

I was afraid of writing the uitypeditor myself, the only thing I can't
figure out is how to do it. Example:

class Sample
{
public string Name { get; set; }

public string Description{ get; set; }
}

class Sample will be visible and editable in the propertygrid, how does
the propertygrid that the class has two properties?

The same way it knows about the properties of any object: Reflection.
 
B

Ben Voigt [C++ MVP]

Jeff Johnson said:
The same way it knows about the properties of any object: Reflection.

That's the default implementation of IPropertyDescriptor, but you can easily
make one that does dictionary lookups. And C# 4.0 will probably have one
that uses the IDynamicObject interface.
 

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