CollectionEditor badness in .NET 2.0?

G

Guest

I have a custom CollectionEditor which has been working nicely for a long
time in .NET 1.1. We just converted to .NET 2.0, recompiled everything, got
rid of the deprecated function calls, etc...

Now, when I run my app, I can bring up the collection editor initially with
no problems, but when I attempt to bring it up a second time, within the
lifetime of the app, I get a null reference error from my override on
EditValue, right on the call to base.EditValue. Here is the stack trace:

System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="System.Windows.Forms"
StackTrace:
at System.Windows.Forms.PropertyGrid.set_SelectedObjects(Object[]
value)
at
System.ComponentModel.Design.CollectionEditor.CollectionEditorCollectionForm.UpdateEnabled()
at
System.ComponentModel.Design.CollectionEditor.CollectionEditorCollectionForm.ResumeEnabledUpdates(Boolean updateNow)
at
System.ComponentModel.Design.CollectionEditor.CollectionEditorCollectionForm.OnEditValueChanged()
at
System.ComponentModel.Design.CollectionEditor.CollectionForm.set_EditValue(Object value)
at
System.ComponentModel.Design.CollectionEditor.EditValue(ITypeDescriptorContext context, IServiceProvider provider, Object value)
at
Pathfinder.EditProfileForm.AttribCollectionEditor.EditValue(ITypeDescriptorContext
dc, IServiceProvider sp, Object o) in
C:\VSSBLD\06.09.01\WindowsApplication\Pathfinder\EditProfileForm.cs:line 10055
at
System.Windows.Forms.PropertyGridInternal.GridEntry.EditPropertyValue(PropertyGridView iva)

Are there some new properties and/or methods on the CollectionEditor in .NET
2.0 that we need to be aware of?

Thanks,
-- TB
 
G

Guest

Some additional information... After debugging awhile I notice that
CollectionEditor is created only once, apparently the first time any instance
of the collection tagged with the Editor attribute is instantiated. In the
constructor of the CollectionEditor I instantiate a CollectionForm object.

The fact that I'm reusing the underlying CollectionForm every time I try to
edit a collection seems to be at the heart of the problem. That is, if in my
EditValue override I explicitly Dispose of the current CollectionForm,
instantiate a new one, and initialize it then my problem goes away.

What I don't know is whether this is introducing any subtle problems, or
whether it is, indeed, the right approach? I've found the documentation for
using collection editors to be slight, at best. Perhaps someone can point me
to something good, especially for .NET 2.0.

Thanks,
-- TB
 

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