473,406 Members | 2,336 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,406 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 2312
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.