473,396 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

CollectionBase OnInsert

Hi all,

I have subclassed the CollectionEditor object in order to
override its OnInsert and OnRemove methods (because I am
exposing some properties (including a collection property)
of a class object at runtime with a PropertyGrid, and
needed to know when the user was adding objects to, or
removing objects from, the collection. My question is: Can
I use the OnInsert method to block the user from modifying
collection if the object to be added/removed fails some
test? OnInsert and OnRemove just return "void", so I don't
see how, but the docs suggest that it can be done.

One complication of using the CollectionEditor is that it
seems not to add/remove objects by calling the collection
class's Add or Remove methods (removal, for instance,
seems to just happen somehow via
(CollectionEditor.DestroyInstance()), but rather by
grabbing the whole inner list, working with it "offline",
and then just plunking it back in.

Any ideas?
Jul 21 '05 #1
2 1872
You can stop the user adding an object to the collection by throwing an
Exception/ArgumentException in the OnValidate methods of the CollectionBase
class. This will force the user to either correct the Object or remove it.

You can use the CollectionEditor's CanRemoveInstance() Method to stop the
user removing an object.

"m. pollack" <an*******@discussions.microsoft.com> wrote in message
news:0d****************************@phx.gbl...
Hi all,

I have subclassed the CollectionEditor object in order to
override its OnInsert and OnRemove methods (because I am
exposing some properties (including a collection property)
of a class object at runtime with a PropertyGrid, and
needed to know when the user was adding objects to, or
removing objects from, the collection. My question is: Can
I use the OnInsert method to block the user from modifying
collection if the object to be added/removed fails some
test? OnInsert and OnRemove just return "void", so I don't
see how, but the docs suggest that it can be done.

One complication of using the CollectionEditor is that it
seems not to add/remove objects by calling the collection
class's Add or Remove methods (removal, for instance,
seems to just happen somehow via
(CollectionEditor.DestroyInstance()), but rather by
grabbing the whole inner list, working with it "offline",
and then just plunking it back in.

Any ideas?

Jul 21 '05 #2
Hi Mick,

Thanks again for responding.
OnValidate? I'll give that a go. I am interested in being
able to substitute a different object for the one being
added - in other words I want to replace the object
created by the Editor with a same-type object of my own
creation, with various settings of its data members. I'm
hoping I can do something like simply replace the object
reference of the passed-in argument with the new one.
Anyway, I'll try.. thanks!

PS ...you'd think they might make this gizmo a little more
developer-friendly! Wherever there is user input,
developers are going to want to control the process --
this CollectionEditor does all of this in avery non-
intuitive way (why, for example, can't OnInsert, instead
of returning 'void', return a bool that cancels the
operation if false?). If it would simply call the
appropriate methods in the collection class (Remove, Add,
etc.) instead of all this behind-the-scenes monkeying
about, life would be much simpler...

MP

-----Original Message-----
You can stop the user adding an object to the collection by throwing anException/ArgumentException in the OnValidate methods of the CollectionBaseclass. This will force the user to either correct the Object or remove it.
You can use the CollectionEditor's CanRemoveInstance() Method to stop theuser removing an object.

"m. pollack" <an*******@discussions.microsoft.com> wrote in messagenews:0d****************************@phx.gbl...
Hi all,

I have subclassed the CollectionEditor object in order to override its OnInsert and OnRemove methods (because I am
exposing some properties (including a collection property) of a class object at runtime with a PropertyGrid, and
needed to know when the user was adding objects to, or
removing objects from, the collection. My question is: Can I use the OnInsert method to block the user from modifying collection if the object to be added/removed fails some
test? OnInsert and OnRemove just return "void", so I don't see how, but the docs suggest that it can be done.

One complication of using the CollectionEditor is that it seems not to add/remove objects by calling the collection class's Add or Remove methods (removal, for instance,
seems to just happen somehow via
(CollectionEditor.DestroyInstance()), but rather by
grabbing the whole inner list, working with it "offline", and then just plunking it back in.

Any ideas?

.

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Steve M | last post by:
I have subclassed CollectionBase. I have also implemented GetEnumerator(). I have tried to set the DataSource of a DataGrid to an instance of my subclass. However, the items in the grid are not...
2
by: m.pollack | last post by:
Hi all, I have an application which uses a class object that contains a collection. In order to use the PropertyGrid control to expose properties to the user at runtime, I created a...
1
by: m. pollack | last post by:
Hi all, I'm still trying to get to the bottom of the problem I am having with the CollectionBase class and the Object Collection Editor. Briefly put, I am exposing a strongly-typed collection...
5
by: Eric Johannsen | last post by:
I have a simple object that inherits from CollectionBase and overrides the Count property: namespace MyTest { public class CollTest : System.Collections.CollectionBase { public override int...
2
by: Samuel R. Neff | last post by:
What's the advantage of inheriting from CollectionBase as opposed to just implementing IList? It seems that it saves you from having to implement a few properties (Clear, CopyTo, Count,...
4
by: dotnw | last post by:
If the answer is "to make strongly typed collections", then I can do this with an ArrayList by taking advantage of the Shadows keyword, as follows: Public Class clsMyClass Inherits...
2
by: m. pollack | last post by:
Hi all, I have subclassed the CollectionEditor object in order to override its OnInsert and OnRemove methods (because I am exposing some properties (including a collection property) of a class...
2
by: adriaandavel | last post by:
Hi all, I am trying to use a collection of String Arrays in an inherited instance of CollectionBase, but the InnerList.IndexOf does not seem to work, any ideas? My code is: public void...
5
by: Tony | last post by:
Hello! Here I have a collection class Cards which is derived from the Base class CollectionBase. This class Cards is a container for Card object. Now to my question at the bottom of this class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.