Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > VB.NET > Windows Forms

Windows Forms Discussion related to Winforms application development

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-02-2007, 1:03 PM
JaedenRuiner's Avatar
VB.NET Forum Master
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Aug 2007
Age: 31
Posts: 340
Reputation: 80
JaedenRuiner probably authored a book by nowJaedenRuiner probably authored a book by nowJaedenRuiner probably authored a book by now
Default Collection & List.

Okay,

I'm inheriting from CollectionBase. I have an add method that calls List.Add as the examples suggest.

I'm not too bright here, but how in the world does "Add()" cause an "index out of bounds" error????!?!?!?!?!

I'm Adding? THe Index is never an issue.

If I were Inserting, then okay, but i'm not, so the index is determined as the last item in the list and voila.

Any ideas why this is happening?

THanks
Jaeden "Sifo Dyas" al'Raec Ruiner
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 11-02-2007, 2:50 PM
JaedenRuiner's Avatar
VB.NET Forum Master
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Aug 2007
Age: 31
Posts: 340
Reputation: 80
JaedenRuiner probably authored a book by nowJaedenRuiner probably authored a book by nowJaedenRuiner probably authored a book by now
Default Urgent: Why, oh why, oh why....

THis is the error i get upon executing
CollectionBase.List.Add()

And I don't get HOW it can even generate an IndexOutOfRangeException(). I mean, forget why it happens, i want to know HOW because this doesn't make any sense.

Quote:
Exception System.IndexOutOfRangeException was thrown in debuggee:
Index was outside the bounds of the array.

System.Collections.IList.Add()
Add() - C:\Documents and Settings\skendrick\My Documents\SharpDevelop Projects\UniversalTool\PendingTasks.vb:100,4
Add() - C:\Documents and Settings\skendrick\My Documents\SharpDevelop Projects\UniversalTool\PendingTasks.vb:113,3
Thanks
Jaeden "Sifo Dyas" al'Raec Ruiner
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-04-2007, 12:59 AM
jmcilhinney's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Aug 2004
Location: Sydney, Australia
Age: 40
Posts: 6,006
Reputation: 538
jmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalist
Default

If you're using .NET 2.0 as your profile says then you shouldn't be inheriting CollectionBase at all. You should be inheriting System.Collections.ObjectModel.Collection(Of T), where T is the type of the items the collection will store. For instance, to create a strongly-typed collection of Thing objects you declare the class like this:
Code:
Public Class ThingCollection
    Inherits System.Collections.ObjectModel.Collection(Of Thing)
End Class
That's all you need. Unlike the CollectionBase class there's no need to declare any members at all if you only want standard functionality because it's ALL inherited from Collection(Of Thing). Only if you need to do extra processing when an item is added or the like do you need to add any code at all.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 10:31 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.