Options for collections class

What options do I have for creating a collection class that is bindable.
For example, something similiar to creating a class like this that inherits
from CollectionBase
 
 Public Class CustomerList
        Inherits CollectionBase
  End Class

Could I create a custom class that inherits from a Generic list?
LVL 8
JRockFLAsked:
Who is Participating?
 
Joel CoehoornConnect With a Mentor Director of Information TechnologyCommented:
The point of BindingList is to save you work.  Before .Net or generics you would have had to create your own classes for customer and product collections, and pass around instances of those types.  You'd probably name them CustomerCollection and ProductCollection, and indeed there are a smattering of those custom types still in the base class library.

Now, you don't need to create those types at all.  All the work is done for your.  CustomerCollection and ProductCollection don't need to exist as types.  Just create a BindingList<Customer> when you need one instead.
0
 
Bob LearnedCommented:
Something like the BindingList<T> generics list?
0
 
JRockFLAuthor Commented:
Where is bindinglist located? i cant seem to find it?
What's the difference between binding list and list?

I wanted to have a standalone class for each object
For example, something like this... but I have not seen it down with generics..

Imports System.Collections.Generic
Public Class CustomerList
    Inherits List(Of Customer)
End Class
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
Joel CoehoornDirector of Information TechnologyCommented:
Inherit System.Collections.CollectionBase
0
 
Joel CoehoornDirector of Information TechnologyCommented:
There are a few more complete options in System.Collection.ObjectModel you might look at as well.
0
 
Bob LearnedCommented:
With System.ComponentModel.BindingList<T>, you don't need a custom class:

Imports System.ComponentModel

...

Private m_customerList As New BindingList(Of Employee)
0
 
JRockFLAuthor Commented:
How can I manage all of my collections?
I didn't want to have my user class returning a list of itself..
0
 
Bob LearnedCommented:
You should be defining the collections of class instances outside of the class itself.  Usage really depends on how you are intending to use the lists.
0
 
JRockFLAuthor Commented:
So what it make sense to have something like this?

Imports System.ComponentModel
Public Class Collections

Private m_customerList As New BindingList(Of Customer)
Private m_productList As New BindingList(Of Product)

...etc
End Class
0
 
Bob LearnedConnect With a Mentor Commented:
That makes sense on the surface, but where are you going to use those lists?

Are you going to do something like this?

So what it make sense to have something like this?

Imports System.ComponentModel

Public Class Collections

Private m_customerList As New BindingList(Of Customer)
Private m_productList As New BindingList(Of Product)

Public ReadOnly Property CustomerList As BindingList(Of Customer)
  Get
     Return m_customerList
  End Get
End Property

Public ReadOnly Property ProductList As BindingList(Of Product)
  Get
     Return m_productList
  End Get
End Property

End Class
0
 
JRockFLAuthor Commented:
jcoehoorn:,
Ok, I see what you are saying now.

TheLearnedOne:
I may to return certain customer objects
WHERE CustomerState = 'AZ'

OR WHERE ProductPrice > 20.00
0
 
Bob LearnedCommented:
Are you using 3.5 or 2.0?
0
 
JRockFLAuthor Commented:
Both! :)
0
 
Bob LearnedCommented:
Are you trying to accomplish in 2.0, what you can do with LINQ in 3.5?
0
 
JRockFLAuthor Commented:
Thank you very much, you both have helped.
I'm actually  making my own little code generator, but should probably look into LINQ. Most of the web sites I work on are in 1.1 and 2.0
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.