hi all
i've created a strong named collection which inherits collection base,but
when i try to add to it a nullreferenceexception blows.
the code is as listed below. do i have to init the list myself.
any hints...please!
thanks all
Public Class NewKeys
Inherits BaseCollection
Default Public Property Item(ByVal Index As Integer) As NewKey
Get
Return CType(list(Index), NewKey)
End Get
Set(ByVal Value As NewKey)
List(Index) = Value
End Set
End Property
Public Overrides ReadOnly Property Count() As Integer
Get
Return (MyBase.List.Count())
End Get
End Property
Public Function Add(ByVal value As NewKey) As Integer
Try
Return List.Add(value)
Catch e As Exception
messagebox.show(e.ToString) <------------ it blows here
debug.writeline(e.tostring())
End Try
End Function 'Add
Public Function IndexOf(ByVal value As NewKey) As Integer
Return List.IndexOf(value)
End Function 'IndexOf
Public Sub Insert(ByVal index As Integer, ByVal value As NewKey)
List.Insert(index, value)
End Sub 'Insert
Public Sub Remove(ByVal value As NewKey)
List.Remove(value)
End Sub 'Remove
Public Function Contains(ByVal value As NewKey) As Boolean
' If value is not of type newkey, this will return false.
Return List.Contains(value)
End Function
End Class
Sooraj PM - 17 May 2004 09:36 GMT
H
You should never create a derived class from BaseCollection. Instead use the CollectionBase class. The BaseCollection class is not intended to use byt the application developer
Regard
Soora
Microsoft India Community Star
Majed - 17 May 2004 12:26 GMT
thanks sooraj
it is ok after modifying the code accordingly
majed
> Hi
>
> You should never create a derived class from BaseCollection. Instead use the CollectionBase class. The BaseCollection class is not intended to use
byt the application developer.
> Regards
>
> Sooraj
> Microsoft India Community Star
Dmitriy Lapshin [C# / .NET MVP] - 17 May 2004 12:45 GMT
You might also consider using the InnerList property to increase
performance, if you don't need events such as ItemAdded to be fired.
> thanks sooraj
> it is ok after modifying the code accordingly
[quoted text clipped - 10 lines]
> > Sooraj
> > Microsoft India Community Star
EricJ - 17 May 2004 11:04 GMT
> messagebox.show(e.ToString) <------------ it blows here
try
e.Message
eric
> hi all
> i've created a strong named collection which inherits collection base,but
> when i try to add to it a nullreferenceexception blows.
> the code is as listed below. do i have to init the list myself.
> any hints...please!
> thanks all
Majed - 17 May 2004 12:27 GMT
hi
e.tostring gives me more information
thanks
> > messagebox.show(e.ToString) <------------ it blows here
> >
[quoted text clipped - 9 lines]
> > any hints...please!
> > thanks all
Jay B. Harlow [MVP - Outlook] - 17 May 2004 14:09 GMT
Majed,
> Public Class NewKeys
> Inherits BaseCollection
Have you tried inheriting from System.Collection.CollectionBase instead of
System.Windows.Forms.BaseCollection?
CollectionBase contains a List property for you ready to use, while
BaseCollection requires you to override the List property and return an
ArrayList to use.
Overall CollectionBase and other classes from System.Collection &
System.Collection.Specialized are the classes you should be using...
Hope this helps
Jay
> hi all
> i've created a strong named collection which inherits collection base,but
[quoted text clipped - 76 lines]
>
> End Class
Majed - 17 May 2004 15:45 GMT
> Majed,
> > Public Class NewKeys
[quoted text clipped - 12 lines]
> Hope this helps
> Jay
it sure dose
thanks