Solved

Options for collections class

Posted on 2008-06-23
15
154 Views
Last Modified: 2010-04-24
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?
0
Comment
Question by:JRockFL
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 3
15 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 21849061
Something like the BindingList<T> generics list?
0
 
LVL 8

Author Comment

by:JRockFL
ID: 21849185
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
 
LVL 18

Expert Comment

by:jcoehoorn
ID: 21849206
Inherit System.Collections.CollectionBase
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:jcoehoorn
ID: 21849215
There are a few more complete options in System.Collection.ObjectModel you might look at as well.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 21849271
With System.ComponentModel.BindingList<T>, you don't need a custom class:

Imports System.ComponentModel

...

Private m_customerList As New BindingList(Of Employee)
0
 
LVL 8

Author Comment

by:JRockFL
ID: 21849374
How can I manage all of my collections?
I didn't want to have my user class returning a list of itself..
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 21849395
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
 
LVL 8

Author Comment

by:JRockFL
ID: 21849450
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
 
LVL 18

Accepted Solution

by:
jcoehoorn earned 250 total points
ID: 21849513
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
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 250 total points
ID: 21849521
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
 
LVL 8

Author Comment

by:JRockFL
ID: 21849651
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 21849672
Are you using 3.5 or 2.0?
0
 
LVL 8

Author Comment

by:JRockFL
ID: 21849704
Both! :)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 21849727
Are you trying to accomplish in 2.0, what you can do with LINQ in 3.5?
0
 
LVL 8

Author Closing Comment

by:JRockFL
ID: 31469890
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question