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

CollectionBase.OnSetComplete

Can anyone tell me what the CollectionBase.OnSetComplete() overridable
method is supposed to be used for?

MyCollectionClass(Index) = Object triggers this method but why does
"setting" in a collection class actually do? Reset the enumerator?

Sorry for the cross group posting.

Any insight would be greatly appreciated

Shannon Richards
BBA, AIT, MCP
Nov 21 '05 #1
3 1457
"Shannon Richards" <sr**********@hotmail.com> wrote in message news:uJ**************@TK2MSFTNGP09.phx.gbl...
Can anyone tell me what the CollectionBase.OnSetComplete() overridable method is supposed to be used for?


It's a protected sub that you can override in your CollectionBase
subclass, and it is called by the .NET Framework after anybody
assigns a new object to this collection. There's a companion sub,
OnSet( ), that gets called immediately before the new object joins
the collection. OnSetComplete( ) is called immediately after the
new object has joined the collection.

The arguments to OnSetComplete( ) let you examine the object
that used to be in your collection at the given index, as well as the
new object. Here are three possible scenarios that may require
special handling after an object in the collection has been set (i.e.,
not inserted, added, or removed, but merely a new object assigned
in-place within the collection).

1. You may decide in your handling of OnSetComplete( )
to reject the assignment, and replace the new object with the old
object (maybe the new object fails to meet some business rule
that your collection requires).

2. Perhaps you're tracking viewstate for the objects in your
collection (e.g., maybe your collection holds the buttons of a
toolbar control), and you can check the new object to see if
it's already tracking viewstate and if not, cause it to start
tracking viewstate.

3. Maybe everytime your collection changes, it needs to fire
an event that notifies another object in your application. For
example, your collection may hold e-mail messages from several
automated build servers across an enterprise. Anytime a new
e-mail arrives in the collection, or an administrator has logged
on and changed the status flags of an existing e-mail, this
collection needs to be able to add a record to the Event Log
or a database.

For more information (please excuse the line-wrap in this URL, it
should all be one-line),

http://msdn.microsoft.com/library/en...pleteTopic.asp
Derek Harmon
Nov 21 '05 #2
Derek,
Your reply was in my mind the perfect reply to a question. It was not a
"this is how I would do it", or a "go google for your answer". It was a
eloquently crafted reply that shows both a knowledge of the easy answer to
the question and most importantly a path to the answer as to why and how you
would leverage this information with an application.

Hats off

Thanks
Lloyd Sheen

"Derek Harmon" <lo*******@msn.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
"Shannon Richards" <sr**********@hotmail.com> wrote in message
news:uJ**************@TK2MSFTNGP09.phx.gbl...
Can anyone tell me what the CollectionBase.OnSetComplete() overridable
method is supposed to be used for?


It's a protected sub that you can override in your CollectionBase
subclass, and it is called by the .NET Framework after anybody
assigns a new object to this collection. There's a companion sub,
OnSet( ), that gets called immediately before the new object joins
the collection. OnSetComplete( ) is called immediately after the
new object has joined the collection.

The arguments to OnSetComplete( ) let you examine the object
that used to be in your collection at the given index, as well as the
new object. Here are three possible scenarios that may require
special handling after an object in the collection has been set (i.e.,
not inserted, added, or removed, but merely a new object assigned
in-place within the collection).

1. You may decide in your handling of OnSetComplete( )
to reject the assignment, and replace the new object with the old
object (maybe the new object fails to meet some business rule
that your collection requires).

2. Perhaps you're tracking viewstate for the objects in your
collection (e.g., maybe your collection holds the buttons of a
toolbar control), and you can check the new object to see if
it's already tracking viewstate and if not, cause it to start
tracking viewstate.

3. Maybe everytime your collection changes, it needs to fire
an event that notifies another object in your application. For
example, your collection may hold e-mail messages from several
automated build servers across an enterprise. Anytime a new
e-mail arrives in the collection, or an administrator has logged
on and changed the status flags of an existing e-mail, this
collection needs to be able to add a record to the Event Log
or a database.

For more information (please excuse the line-wrap in this URL, it
should all be one-line),
http://msdn.microsoft.com/library/en...pleteTopic.asp
Derek Harmon

Nov 21 '05 #3
Hello: Thank you for your reply. I appreciate the detailed
explanation...very helpful!!! Below I have outlined a related issue I have
been trying to solve...Any insight would be greatly appreciated :-).

I currently have a situation where I have a Collection class derived from
CollectionBase. In this custom collection object I have implemented all the
required interfaces to support complex data binding.
I want child objects to notify the collection class whenever a change occurs
(example: Property value changed). I then want the collection object to
raise the "ListChanged" event defined in the IBindingList interface. This
event will notify any complex controls bound to my collection class that
they should refresh their display.

example (child object - Name property):
Public Property Name() As String
Get
Return ms_Name
End Get
Set(ByVal Value As String)
' This event supports simple data binding
RaiseEvent NameChanged(Me, New EventArgs)

' This causes the OnSetComplete() method of the collection class to
fire
Dim li_Index as Integer = mo_ParentList.IndexOf(Me)
mo_ParentList(li_Index) = Me
End Set
End Property

This code "sets" the current item in the collection to the now modified
child object...This triggers the OnSet() and OnSetComplete() methods of the
collection class. I am currently raising the "ListChanged" event in the
OnSetComplete() method of the collection class...

This notification works perfectly except when I change properties on
multiple objects inside a loop. I get an error because the Enumerator gets
messed up when the "set" occurs inside a loop.

example (Collection Object - Save method)
....
Dim lo_Object as Object

For Each lo_Object in MyCollectionObject
lo_Object.Property = "Some Value"
lo_Object.Save()
Next
....

Any thoughts on a better way to notify the parent object that a change has
occurred in a child object? At this point I think it would be better to
raise an event (example: a ListItemChanegd() event) from the child object
that the CollectionClass can listen for. Then the Collection class could in
turn raise the ListChanged event to facilitate the chain of notification...

Thank you again for the help!!!
Shannon Richards
BBA, AIT, MCP



"Derek Harmon" <lo*******@msn.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
"Shannon Richards" <sr**********@hotmail.com> wrote in message
news:uJ**************@TK2MSFTNGP09.phx.gbl...
Can anyone tell me what the CollectionBase.OnSetComplete() overridable
method is supposed to be used for?


It's a protected sub that you can override in your CollectionBase
subclass, and it is called by the .NET Framework after anybody
assigns a new object to this collection. There's a companion sub,
OnSet( ), that gets called immediately before the new object joins
the collection. OnSetComplete( ) is called immediately after the
new object has joined the collection.

The arguments to OnSetComplete( ) let you examine the object
that used to be in your collection at the given index, as well as the
new object. Here are three possible scenarios that may require
special handling after an object in the collection has been set (i.e.,
not inserted, added, or removed, but merely a new object assigned
in-place within the collection).

1. You may decide in your handling of OnSetComplete( )
to reject the assignment, and replace the new object with the old
object (maybe the new object fails to meet some business rule
that your collection requires).

2. Perhaps you're tracking viewstate for the objects in your
collection (e.g., maybe your collection holds the buttons of a
toolbar control), and you can check the new object to see if
it's already tracking viewstate and if not, cause it to start
tracking viewstate.

3. Maybe everytime your collection changes, it needs to fire
an event that notifies another object in your application. For
example, your collection may hold e-mail messages from several
automated build servers across an enterprise. Anytime a new
e-mail arrives in the collection, or an administrator has logged
on and changed the status flags of an existing e-mail, this
collection needs to be able to add a record to the Event Log
or a database.

For more information (please excuse the line-wrap in this URL, it
should all be one-line),
http://msdn.microsoft.com/library/en...pleteTopic.asp
Derek Harmon

Nov 21 '05 #4

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,...
0
by: Shannon Richards | last post by:
Hello All: Can anyone tell what exactly this method is supposed to be used for? I have a class that derives from CollectionBase. This class overrides the OnSetComplete() method to raise an event...
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,...
0
by: Ramiro Escobar via DotNetMonster.com | last post by:
I'm try to follow the .NET SDK Rockford Lotkha's example regarding a collection inherited from CollectionBase that binds to a Windows Forms Datagrid. My problem is that I cannot raise the...
0
by: LIJO CHEERAN | last post by:
Hello friends I am trying to study about CollectionBase. I have inherited CollectionBase in the class TheCollection.cs. I am using the “TheCollection. in an aspx page to store objects...
3
by: Tony Johansson | last post by:
Hello! Sorry for opening up this task again. I want to fully understand this List that is return from CollectionBase. According to you is List in CollectionBase implemented something like...
1
by: graeme gorman | last post by:
Hi I have a class that inherits CollectionBase - now what I want is to be able to validate data when it is updated in the List (I need to make sure that certain values are not duplicates) so I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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
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
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
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...

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.