Click here to Skip to main content
15,889,281 members
Home / Discussions / C#
   

C#

 
GeneralRe: Returning a collection class Pin
Frank Olorin Rizzi15-Jul-03 6:28
Frank Olorin Rizzi15-Jul-03 6:28 
GeneralRe: Returning a collection class Pin
Andrew Bromfield15-Jul-03 6:50
Andrew Bromfield15-Jul-03 6:50 
GeneralRe: Returning a collection class Pin
Frank Olorin Rizzi15-Jul-03 7:18
Frank Olorin Rizzi15-Jul-03 7:18 
GeneralRe: Returning a collection class Pin
Andrew Bromfield15-Jul-03 8:06
Andrew Bromfield15-Jul-03 8:06 
GeneralRe: Returning a collection class Pin
Frank Olorin Rizzi15-Jul-03 12:19
Frank Olorin Rizzi15-Jul-03 12:19 
GeneralRe: Returning a collection class Pin
Andrew Bromfield16-Jul-03 4:13
Andrew Bromfield16-Jul-03 4:13 
GeneralRe: Returning a collection class Pin
Frank Olorin Rizzi16-Jul-03 4:49
Frank Olorin Rizzi16-Jul-03 4:49 
GeneralRe: Returning a collection class Pin
Andrew Bromfield16-Jul-03 10:36
Andrew Bromfield16-Jul-03 10:36 
OK, I've got it now. The method below validates the new object by getting its type and making sure its of type IndividualCustomer. The runtime error I was seeing in the beginning (the cause of this whole thread) was the error message contained in the exception arguments (throw new ArgumentException("value must be of type IndividualCustomer.", "value");". According to Microsoft this method is used to:

"OnValidate can be used to impose restrictions on the type of objects that are accepted into the collection. The default implementation prevents a null reference (Nothing) from being added to or removed from the underlying System.Collections.ArrayList."

The question is why is the value null after I perform the IndividualCustomerCollection.Add function?? When I remove the code, the IndividualCustomer is added to the constructor without any problems. According to Microsoft :

"The On* methods are invoked only on the instance returned by the List property, but not on the instance returned by the InnerList property."

**Definition**
The CollectionBase.List Property - Gets an IList containing the list of elements (objects) in the CollectionBase instance.

By this definition, the onValidate method should execute after the the List property returns the list of objects in my instance of the IndividualCustomerCollection. I don't recall overriding the CollectionBase.List property in my IndividualCustomerCollection class. I'll have to check this when I get home and make the appropriate changes.


/*Implementation of CollectionBase Property
*Performs additional custom processes when
*validating a value.*/

protected override void OnValidate(Object value)

{

if (value.GetType() != Type.GetType("IndividualCustomer"))

{

throw new ArgumentException("value must be of type IndividualCustomer.", "value");

}

}


You'll have to excuse me, I'm knew to creating data binding collections and I want to make sure I understand this inside and out. It's nice to use examples from MSDN, but if you don't take the time to understand everything your implementing you'll run into these kinds of problems. I have definitely learned my lesson Smile | :) Does anyone have any suggestions as to why my value is null?

Thanks,

Andrew


GeneralDrawing on Desktop Pin
Juergen15-Jul-03 3:48
Juergen15-Jul-03 3:48 
GeneralRe: Drawing on Desktop Pin
jtmtv1816-Jul-03 16:50
jtmtv1816-Jul-03 16:50 
GeneralRe: Drawing on Desktop Pin
Juergen16-Jul-03 22:08
Juergen16-Jul-03 22:08 
GeneralRe: Drawing on Desktop Pin
jtmtv1816-Jul-03 22:34
jtmtv1816-Jul-03 22:34 
GeneralRe: Drawing on Desktop Pin
Juergen16-Jul-03 22:47
Juergen16-Jul-03 22:47 
GeneralRe: Drawing on Desktop Pin
jtmtv1816-Jul-03 23:04
jtmtv1816-Jul-03 23:04 
GeneralSerialization in C# Pin
Stephane David14-Jul-03 22:38
Stephane David14-Jul-03 22:38 
GeneralRe: Serialization in C# Pin
Nathan Blomquist15-Jul-03 3:57
Nathan Blomquist15-Jul-03 3:57 
GeneralRe: Serialization in C# Pin
Stephane David15-Jul-03 4:33
Stephane David15-Jul-03 4:33 
GeneralRe: Serialization in C# Pin
Nathan Blomquist15-Jul-03 9:55
Nathan Blomquist15-Jul-03 9:55 
GeneralRe: Serialization in C# Pin
Anonymous16-Jul-03 6:03
Anonymous16-Jul-03 6:03 
GeneralMSMQ Question Pin
ripsi14-Jul-03 19:55
ripsi14-Jul-03 19:55 
Generalhelp me, how to autoscroll in richtextbox Pin
KETUINHA14-Jul-03 17:31
KETUINHA14-Jul-03 17:31 
GeneralRe: help me, how to autoscroll in richtextbox Pin
J. Dunlap14-Jul-03 19:06
J. Dunlap14-Jul-03 19:06 
GeneralRe: help me, how to autoscroll in richtextbox Pin
KETUINHA14-Jul-03 20:49
KETUINHA14-Jul-03 20:49 
GeneralRe: help me, how to autoscroll in richtextbox Pin
J. Dunlap14-Jul-03 21:05
J. Dunlap14-Jul-03 21:05 
GeneralRe: help me, how to autoscroll in richtextbox Pin
KETUINHA14-Jul-03 21:16
KETUINHA14-Jul-03 21:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.