By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,745 Members | 1,897 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,745 IT Pros & Developers. It's quick & easy.

CollectionEditor BUG

P: n/a
<I've reposted this here as it was slipping away over the horizon on the C# group

Hi all,

I've been writing an application that uses a class object (call it Element) that I need to expose to the user at runtime for editing. To do this, I've been using the PropertyGrid control. The Element object has a collection property that contains references to other Elements (its purpose is to allow the users to generate XML schemas at runtime, in which elements can be nested to arbitrary depth). The PropertyGrid control opens an instance of the CollectionEditor class when the user opens the collection property of a selected Element for editing. The CollectionEditor class displays in its right panel another PropertyGrid for editing the properties of the selected colection member, and in its left panel has a listbox containing the members of the collection. One useful feature is that the user can add a new instance of the collection type (the default is Object) by clicking an Add button. This generates a new instance and adds it to the collection (in a rather complicated way, as it turns out). To support this, I've written a strongly-typed collection class for Element objects, so that the CollectionEditor knows what type to generate, and what properties to display for editing

Here's the problem: When a user clicks "Add", a new instance of the collection type is added (which in this case also contains its own collection). If the user then goes to edit the collection property of the new instance, yet another Collection Editor pops up. The user can click "Add" in this window too, which will add a new child Element to the new Object's collection. In this way the user can "drill down", adding children to children, etc., with no apparent limit. The difficulty arises when the user decides to save, which involves clicking "OK" on the topmost CollectionEditor window, then on the one below it, etc... However, although the topmost one closes just fine, the ones below pop up a messagebox saying "Error: Object reference not set to an instance of an object." This is not a standard system unhandled-exception popup, but seems instead to be some custom message, probably generated in a "catch" block somewhere in the editor source code. I have exhaustively examined my own code, put breakpoints everywhere, made sure that Element constructors are being called at each level, etc., but have found no problem. The CollectionEditor seems to be doing alot of work behind the scenes over and above just adding/removing things from the existing collection, and the documentation of what it is doing seems to be nonexistent.

Sorry this was such a long-winded post, but it is a tricky thing to explain. Can anyone shed any light on this

Thanks, M


Jul 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.