473,406 Members | 2,390 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.

List in collectionbase

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
4 1169
>
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
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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Majed | last post by:
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...
2
by: Colin Basterfield | last post by:
Hi, I have a list which is derived from CollectionBase, and it contains a list of User objects, which I want to Serialize out to an XML file. Is there anywhere where I can find how to decode...
2
by: Colin Basterfield | last post by:
Hi, I have two lists, the first is the complete list, so call it PermList, the second is a subsection of that list, call this TempList, both are of the same type, naemly strongly typed and...
3
by: jason | last post by:
Hello. I've got this simple collection populate code I downloaded from the net (sorry can't find source now) I'm trying to test, but I can't seem to get it to work. Any help would be greatly...
3
by: SStory | last post by:
For an owner drawn list box, I have a collection that represents some graphics objects in my app. I inherited the collection class from collectionbase. It would be nice to somehow just set the...
3
by: moondaddy | last post by:
I wrote my own List class which I use to bind to list controls. this class inherits CollectionBase and implements IBindingList. This class contains a list of business classes such as customers...
8
by: Yuk Tang | last post by:
I am tearing my hair out over this, since I can't see what I'm doing wrong (duh, if I knew, I wouldn't be asking the question). I am adding Field items to a Field Collection, but for some reason...
2
by: Demetri | last post by:
I have a collection class that inherits from CollectionBase. I am using the List.Remove method to remove an object in the collection. When I use it, I get the following error: Exception Details:...
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...
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...
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
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.