PropertyDescriptorCollection.Remove()

  • Thread starter Thread starter FrankYM
  • Start date Start date
F

FrankYM

Hi all,

I have a general question concerning the capability of the
PropertyDescriptorCollection. It seems to be impossible to remove a
PropertyDescriptor savely using Remove or RemoveAt. I use framework
1.1. Why does the following code always crash resulting in the error
message "Source array was not long enough. Check srcIndex and length,
and the array's lower bounds.":

PropertyDescriptorCollection PDC = new
PropertyDescriptorCollection(null);
PDC.Add(new MyItemDescriptor(null, "first", ""));
PDC.Add(new MyItemDescriptor(null, "second", ""));
PDC.RemoveAt(0);

But removing the second element works this time:

PropertyDescriptorCollection PDC = new
PropertyDescriptorCollection(null);
PDC.Add(new MyItemDescriptor(null, "first", ""));
PDC.Add(new MyItemDescriptor(null, "second", ""));
PDC.RemoveAt(1);

For me it's impossible to foresee when it will fail, sometimes it's
removable sometimes not.

Thanks in advance,

Frank
 
Im having the same problem. I stepped through my code, and the Length of
the PropertyDescriptorCollection implementation was 2, when I got this
error.

It was trying to remove element at position 0.

Brian Takita
 
Back
Top