Editing object in an ArrayList using the PropertyGrid

  • Thread starter Thread starter deleria010
  • Start date Start date
D

deleria010

I have a class that I use a PropertyGrid to edit properties in. I have
one property in the class that is an ArrayList. The PropertyGrid
understands the ArrayList(displays Collection on the righthand side)
and lets me edit it(click on the '...' button and an object collection
editor window opens up).

When I try to edit the objects in the list using the collection editor
window, I can't because their properties and the values of the
properties on the righthand side are 'grayed out'. I can add and
remove items but I can't change the value of the items I add because
the properties are 'grayed out'. I want to be able to edit not only
the ArrayList but each item's value in the list. Is there anyway to do
this?

Here is the code that describes the property for the ArrayList:

[CategoryAttribute("Camera Settings"),
DescriptionAttribute("A list of exposure times in ms")]
public ArrayList ExposureTimes
{
get
{
return this.exposureTimes;
}
set
{
this.exposureTimes = value;
}
}

Thanks for your time,
Kristin
 
I have found some work arounds. If the variable is an array of native
types, the PropertyGrid has no problem displaying the values so that
they can be edited. But this opens up the problem of managing the
array yourself, which an ArrayList takes care of.

So I created my own array list class that expands the list as needed
and provides all the methods that I was already using. I had to add a
hint to have the PropertyGrid display the values in the array so that
the user can edit them.

[TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))]
just above the class.

What gets displayed in the PropertyGrid is a bit weird. There is the
variable of type MyArrayList than under that, a variable of the actual
array list, then you can expand the array to see and edit the actual
contents of the array. It is not the most ideal solution but it works
for what I need it to do.

Kristin
 
Back
Top