Solved

Creating a base class inheriting BindingList

Posted on 2008-10-14
6
2,286 Views
Last Modified: 2013-11-08
I need the specific code for VB.Net 2.0 - 3.5 to create a BindingList base (abstract) class for my business object 'collections' to inherit from (specifically the 'Persons' below).

The reason I need a base class is that I want to insert some common functionality in it that I do not wish to hand-duplicate in each specific business class and let the power of inheritance do that work.

I have done this sucessfully in the past with .Net 1.1 projects using Collection, but now using BindingList(Of T) with .Net 3.5, which is new to me, it's got me tripped up how not to have to specify the type in the (Of T) of the base class so that I can inherit from it for many different classes in my project and specify the type in each class.

Below is code for example purposeses. I need a base class that clsPersons would inherit from.

Thanks, Jeff







'''' Object '''''

Public Class clsPerson

    Private _Id As Integer

    Private _Name As String

 

    Public ReadOnly Property Id() As Integer

        Get

            Return _Id

        End Get

    End Property

 

    Public Property Name() As String

        Get

            Return _Name

        End Get

        Set(ByVal value As String)

            _Name = value

        End Set

    End Property

 

    Public Sub New(ByVal Name As String, ByVal Id As Integer)

        _Id = Id

        _Name = Name

    End Sub

End Class

 

'''' Collection ''''

Imports System.ComponentModel

Public Class clsPersons

    'How to make this non-type specific for inheritance?

    Inherits BindingList(Of clsPerson)

    Implements IEnumerable

End Class

Open in new window

0
Comment
Question by:JEFFCECCHINI
  • 4
  • 2
6 Comments
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 500 total points
ID: 22723873
public class YourAbstractBase(Of T)
     Inherits BindingList(Of T)
implements IEnumerable(Of T)


end class
0
 

Author Closing Comment

by:JEFFCECCHINI
ID: 31506200
Hi Greg,

Thanks for the reply. I assume that in my 'collection' I must do this to inherit from the abstract class

Public Class clsPersons
    Inherits BindingList(Of clsPerson)
    Implements IEnumerable
End Class

Now, I'm trying to figure out how do enable things like sorting in the abstract class. If you know how, please comment. I can open another question and award more points.

Thanks so much, Jeff
0
 

Author Comment

by:JEFFCECCHINI
ID: 22724517
Oops...Implements IEnumerable in my comment above would be unnecessary
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 37

Expert Comment

by:gregoryyoung
ID: 22724524
No worries points and a dollar will get me a cup of coffee. Here is an example in C# (and explanation), it should be pretty easy to translate to VB.NET.

http://msdn.microsoft.com/en-us/library/ms993236.aspx

Cheers,

Greg
0
 

Author Comment

by:JEFFCECCHINI
ID: 22724672
Thanks Greg, I'm checking this out now.
Since I took the jump from VB.NET 1.1 to VB.NET 3.5, I might as well take advantage of some of the new technology rather than porting my old stuff forward. We'll see if this time allocation proves fruitful.

Jeff
0
 

Author Comment

by:JEFFCECCHINI
ID: 22728200
Hi Greg, I'm having some problems implementing the sorting.
Here's my new question, maybe you could take a look?

http://www.experts-exchange.com/Programming/Languages/.NET/Q_23819265.html

Thanks, Jeff
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

19 Experts available now in Live!

Get 1:1 Help Now