473,394 Members | 1,697 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,394 software developers and data experts.

CollectionBase Remove method - still trying

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
property, using a class derived from CollectionBase, to
the user via the PropertyGrid control's popup Collection
Editor. I need to know when the user has added or removed
objects to the collection. In my collection class I am
implementing the collection interface's Add, Insert,
Remove, and RemoveAt methods, but the Collection Editor
does not seem to call these implemented methods to
manipulate the list. There are some "hook" methods
provided, namely OnInsert, OnInsertComplete, OnRemove, and
OnRemoveComplete, so I tried overriding those methods. If
the user adds to the collection with the Collection
Editor, the OnInsert hook is called, but the OnRemove
method is not called when an object is removed. I can find
absolutely no documentation about this problem, and as far
as my application is concerned it's kind of a show-stopper.
A few people replied to my previous post, but I still have
not found a way around the problem. JD posted that the IL
did in fact seem to be calling the On Remove and
OnRemoveComplete methods, but it sure doesn't seem to be
working when I try it. Mick Doherty posted that the
CollectionEditor might be destroying and recreating the
whole list, and thereby bypassing this code... does
anybody know what is going on with this thing?

Many thanks, MP
Jul 21 '05 #1
1 2311
I had another look at this problem.
You need to override the CollectionEditors DestroyInstance method.

Heres some VB.Net Code, needs a bit more work but it's a start.
You'll need to add a reference to System.Design.dll.

\\\
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing.Design

Public Class MyClass
...
...
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content), _
Editor(GetType(MyCollectionEditor), GetType(UITypeEditor))> _
Public ReadOnly Property MyCollection() As MyCollectionType
Get
Return MyCollectionTypeVariable
End Get
End Property
Private Function ShouldSerializeMyCollection() As Boolean
Return False
End Function
...
...

Friend Class MyCollectionEditor
Inherits CollectionEditor

Public Sub New(ByVal type As System.Type)
MyBase.new(type)
End Sub

Protected Overrides Function CreateCollectionItemType() As
System.Type
Return GetType(MyType)
End Function

Protected Overrides Sub DestroyInstance(ByVal instance As Object)
MyBase.DestroyInstance(instance)
'It's as near as I can get, and only happens if OK is pressed.
If TypeOf instance is MyCollectionTypeItem Then
MsgBox(DirectCast(instance,
MyCollectionItemType).Variable.ToString)
End If
End Sub

End Class

End Class
///
"m. pollack" <an*******@discussions.microsoft.com> wrote in message
news:0a****************************@phx.gbl...
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
property, using a class derived from CollectionBase, to
the user via the PropertyGrid control's popup Collection
Editor. I need to know when the user has added or removed
objects to the collection. In my collection class I am
implementing the collection interface's Add, Insert,
Remove, and RemoveAt methods, but the Collection Editor
does not seem to call these implemented methods to
manipulate the list. There are some "hook" methods
provided, namely OnInsert, OnInsertComplete, OnRemove, and
OnRemoveComplete, so I tried overriding those methods. If
the user adds to the collection with the Collection
Editor, the OnInsert hook is called, but the OnRemove
method is not called when an object is removed. I can find
absolutely no documentation about this problem, and as far
as my application is concerned it's kind of a show-stopper.
A few people replied to my previous post, but I still have
not found a way around the problem. JD posted that the IL
did in fact seem to be calling the On Remove and
OnRemoveComplete methods, but it sure doesn't seem to be
working when I try it. Mick Doherty posted that the
CollectionEditor might be destroying and recreating the
whole list, and thereby bypassing this code... does
anybody know what is going on with this thing?

Many thanks, MP

Jul 21 '05 #2

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...
7
by: m. pollack | last post by:
Hi all, I've been using the CollectionBase class to implement a strongly-typed collection, but I have noticed that the RemoveAt method does not seem to call the "On" hook methods (OnRemove,...
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...
0
by: rein.petersen | last post by:
Hi All, Some of you may have encountered complications when trying to serialize an object derived from CollectionBase (implementing ICollection or IEnumerable). Specifically, the...
4
by: Franck Diastein | last post by:
Hi, I have create a TypeSafe collection with CollectionBase, but I don't know how to update an object... Let's say I have an Animal class with Animals collection. Animal has a property named...
1
by: Matthew Roberts | last post by:
Howdy Everyone, I am having trouble understanding the process of creating a type-safe collection by inheriting from the CollectionBase class. I have done it plenty of times, but now that I sit...
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,...
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.