Correctly displaying IDictionary derived class in PropertyGrid

G

Guest

Hi
I have a class which has a property which implements IDictionary which I
would like to display in a propertygrid control. If I add
[TypeConverter(typeof(ExpandableObjectConverter))] the property expands, but
I only get Count, IsReadOnly, Keys and Values properties, all of which are
disabled.

If I implement my property as Dictionary<string, myObj> I get the option to
click on the keys and the values, but these then bring up the input dialog
into which I can't add any new values (for good reason).

List<myObj> works fine of course.

I have googled around and found some articles, but none of these seemed to
work.

Please could anyone advise as to the best way to solve this problem.

Marek
 
S

Stoitcho Goutsev \(100\)

Marek,

What was the question. I kind of missed it. What is that you want to
achieve?
 
G

Guest

Hi Stoitcho
Sorry for the confusion, it's a bit hard to get my requirements down on paper!

The question is how to display an object's property (called MyCollection
say) where the MyCollection property is a class implemented as follows:

class MyCollectionClass : IDictionary<string, MyObjectType>

so that when the object is displayed in the property grid the user can
expand the MyCollection property with say an ellipsis button and then add and
remove objects of the type specified by IDictionary<key, MyObjectType> and
set their values in a manner similar to that had I used List<MyObjectType>
for example.

My current line of attack is as follows:

[Editor(typeof(MyCollectionEditor),
typeof(System.Drawing.Design.UITypeEditor))]
public MyCollectionClass

and then in MyCollectionEditor to the override GetEditStyle and EditValue
and to display a custom form which allows the user to edit the collection and
its contents. The second question therefore is is this approach the right
one in a .NET2 world?

I hope this makes sense.

Marek

Stoitcho Goutsev (100) said:
Marek,

What was the question. I kind of missed it. What is that you want to
achieve?


--
Stoitcho Goutsev (100)

Marek said:
Hi
I have a class which has a property which implements IDictionary which I
would like to display in a propertygrid control. If I add
[TypeConverter(typeof(ExpandableObjectConverter))] the property expands,
but
I only get Count, IsReadOnly, Keys and Values properties, all of which are
disabled.

If I implement my property as Dictionary<string, myObj> I get the option
to
click on the keys and the values, but these then bring up the input dialog
into which I can't add any new values (for good reason).

List<myObj> works fine of course.

I have googled around and found some articles, but none of these seemed to
work.

Please could anyone advise as to the best way to solve this problem.

Marek
 
S

Stoitcho Goutsev \(100\)

Marek,

Have you seen this somewhere in the standard framework controls? If you have
then you can try with the reflector to find out what type of editor
micorosoft guys use. Sometimes it is possible to reuse their. If there is
nothing out of the box I'm afraid you need to write your own as you've
already started.


--
Stoitcho Goutsev (100)

Marek said:
Hi Stoitcho
Sorry for the confusion, it's a bit hard to get my requirements down on
paper!

The question is how to display an object's property (called MyCollection
say) where the MyCollection property is a class implemented as follows:

class MyCollectionClass : IDictionary<string, MyObjectType>

so that when the object is displayed in the property grid the user can
expand the MyCollection property with say an ellipsis button and then add
and
remove objects of the type specified by IDictionary<key, MyObjectType> and
set their values in a manner similar to that had I used List<MyObjectType>
for example.

My current line of attack is as follows:

[Editor(typeof(MyCollectionEditor),
typeof(System.Drawing.Design.UITypeEditor))]
public MyCollectionClass

and then in MyCollectionEditor to the override GetEditStyle and EditValue
and to display a custom form which allows the user to edit the collection
and
its contents. The second question therefore is is this approach the right
one in a .NET2 world?

I hope this makes sense.

Marek

Stoitcho Goutsev (100) said:
Marek,

What was the question. I kind of missed it. What is that you want to
achieve?


--
Stoitcho Goutsev (100)

Marek said:
Hi
I have a class which has a property which implements IDictionary which
I
would like to display in a propertygrid control. If I add
[TypeConverter(typeof(ExpandableObjectConverter))] the property
expands,
but
I only get Count, IsReadOnly, Keys and Values properties, all of which
are
disabled.

If I implement my property as Dictionary<string, myObj> I get the
option
to
click on the keys and the values, but these then bring up the input
dialog
into which I can't add any new values (for good reason).

List<myObj> works fine of course.

I have googled around and found some articles, but none of these seemed
to
work.

Please could anyone advise as to the best way to solve this problem.

Marek
 

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