Solved

Options for collections class

Posted on 2008-06-23
15
145 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
  • 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now