By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,286 Members | 1,589 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,286 IT Pros & Developers. It's quick & easy.

List in collectionbase

P: n/a
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

Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
>
messagebox.show(e.ToString) <------------ it blows here
try
e.Message
eric

"Majed" <am******@hotmail.com> wrote in message
news:ej***************@TK2MSFTNGP11.phx.gbl... 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

Nov 20 '05 #2

P: n/a
hi
e.tostring gives me more information

thanks

"EricJ" <er********@ThiSbitconsult.be.RE> wrote in message
news:e2**************@TK2MSFTNGP12.phx.gbl...

messagebox.show(e.ToString) <------------ it blows here

try
e.Message
eric

"Majed" <am******@hotmail.com> wrote in message
news:ej***************@TK2MSFTNGP11.phx.gbl...
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


Nov 20 '05 #3

P: n/a
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

"Majed" <am******@hotmail.com> wrote in message
news:ej***************@TK2MSFTNGP11.phx.gbl... 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


Nov 20 '05 #4

P: n/a

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:Ok**************@tk2msftngp13.phx.gbl...
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

it sure dose
thanks
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.