Expanded Collection in PropertyGrid doesn't work with the CollectionEditor

  • Thread starter Tilman J. Voelker
  • Start date
T

Tilman J. Voelker

Hi,
I have the following problem an hope anyone can help me.

I have a Collection which can be expanded (with the
ExpandableObjectConverter) and the Items can also be expanded.

The Collection is added to a PropertyGrid.

When I expand the Collection and one item and start the
CollectionEditor of the Collection it works fine. But if I press the
"cancel" or "ok" button of the CollectionEditor a "Index was outside
the bounds of the array." Execption will be thrown.

Thanks Johannes

namespace Collection
{
[TypeConverterAttribute(__typeof(ExpandableObjectConverter))]
public __gc class TestProperty
{
public:
TestProperty(void) : m_test1(S" ") {}

__property String* get_test1() { return m_test1; }
__property void set_test1(String* value) { m_test1 = value; }

private:
String* m_test1;
};


public __gc class CollectionItemPropertyDescriptor;

///////////// MyCollection ////////////////////////////
public __gc class TestCollection : public CollectionBase, public
ICustomTypeDescriptor
{
public:
TestCollection(void) : CollectionBase() {}

void Add(TestProperty* obj)
{
this->List->Add(obj);
}

__property TestProperty* get_Item(int index)
{
return dynamic_cast<TestProperty* >(this->List->get_Item(index));
};

__property void set_Item(int index,TestProperty* value)
{
this->List->set_Item(index,value);
};

// Implementation of interface ICustomTypeDescriptor
String* GetClassName()
{
return GetClassName();
}

AttributeCollection* GetAttributes()
{
return TypeDescriptor::GetAttributes(this,true);
}

String* GetComponentName()
{
return TypeDescriptor::GetComponentName(this, true);
}

TypeConverter* GetConverter()
{
return TypeDescriptor::GetConverter(this, true);
}

EventDescriptor* GetDefaultEvent()
{
return TypeDescriptor::GetDefaultEvent(this, true);
}

PropertyDescriptor* GetDefaultProperty()
{
return TypeDescriptor::GetDefaultProperty(this, true);
}

Object* GetEditor(Type* editorBaseType)
{
return TypeDescriptor::GetEditor(this, editorBaseType, true);
}

EventDescriptorCollection* GetEvents(Attribute* attributes[])
{
return TypeDescriptor::GetEvents(this, attributes, true);
}

EventDescriptorCollection* GetEvents()
{
return TypeDescriptor::GetEvents(this, true);
}

Object* GetPropertyOwner(PropertyDescriptor* pd)
{
return this;
}

PropertyDescriptorCollection* GetProperties()
{
return TypeDescriptor::GetProperties(__typeof(ExpandableObjectConverter));
}

PropertyDescriptorCollection* GetProperties(Attribute*
attributes[]);
};

/////////////// PropertyDescriptor /////////////////////////
public __gc class CollectionItemPropertyDescriptor : public
PropertyDescriptor
{
public:

CollectionItemPropertyDescriptor( TestCollection* coll, int Index )
: PropertyDescriptor( (String::Concat("#", Index.ToString())) , NULL
),
m_Collection( coll ),
m_index( Index )
{
}

__property virtual AttributeCollection* get_Attributes()
{
return new AttributeCollection(NULL);
};

virtual bool CanResetValue(Object* component)
{
return true;
}

__property virtual Type* get_ComponentType()
{
return this->m_Collection->GetType();
};

virtual String* get_DisplayName()
{
return S"Item Name";
};

__property virtual String* get_Description()
{

return S"Für Informationen siehe übergeordnetes Objekt.";
};

virtual Object* GetValue(Object* component)
{
return this->m_Collection->Item[m_index] ?
this->m_Collection->Item[m_index] : NULL;
}

__property virtual bool get_IsReadOnly()
{
return false;
};

__property virtual String* get_Name()
{
return String::Concat("#",m_index.ToString());
};

__property virtual Type* get_PropertyType()
{
return this->m_Collection->Item[m_index] ?
this->m_Collection->Item[m_index]->GetType() : NULL;
};

virtual void ResetValue(Object* component)
{
}

virtual bool ShouldSerializeValue(Object* component)
{
return false;
}

virtual void SetValue(Object* component, Object* value)
{
// this->m_Collection[m_index] = value;
}

private:
TestCollection* m_Collection;
int m_index;
};

PropertyDescriptorCollection*
TestCollection::GetProperties(Attribute* attributes[])
{
PropertyDescriptorCollection* __PropertyDescriptorCollection = new
PropertyDescriptorCollection(NULL);

for( int i = 0 ; i < this->List->Count; i++ )
__PropertyDescriptorCollection->Add(new
CollectionItemPropertyDescriptor(this,i));

return __PropertyDescriptorCollection;
}

}
 

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