Solved

Options for collections class

Posted on 2008-06-23
15
155 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
Industry Leaders: 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

729 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