Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / May 2004

Tip: Looking for answers? Try searching our database.

List in collectionbase

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Majed - 17 May 2004 08:56 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.