Home All Groups Group Topic Archive Search About
Author
8 Feb 2006 11:54 AM
guy
i have a generic class

Public Class ACollection(Of T)
    Inherits BindingList(Of T)

where BaseDataClass is declared mustinherit

i then have some code that loadss the collection

With oSQLDR ' a datareader
                If .HasRows Then
                    Do While .Read = True

                        'Create new instance of appropriate businees object
then populate
                        Dim o As Object = Me.AddNew
                        busObject = CType(o, IDataClass)
                        busObject.clientConnection = Me.ClientConnection
                        busObject.Populate(oSQLDR)
                    Loop
                End If
            End With

this all works fine

however if i change this collection to

Public Class ACollection(Of BaseCLass)

how, when using AddNew in the above code do i get addnew to add the correct
type of object (which inherits from BaseClass)

guyy

Author
8 Feb 2006 6:20 PM
Jim Wooley
I believe you need to change your  line
    Dim o as Object = Me.AddNew
to
    Dim o as T = Me.AddNew

Jim Wooley

Show quoteHide quote
"guy" <g**@discussions.microsoft.com> wrote in message
news:B21B0D32-F6EE-48C5-81B8-001C378D2C2B@microsoft.com...
>i have a generic class
> this all works fine
>
> however if i change this collection to
>
> Public Class ACollection(Of BaseCLass)
>
> how, when using AddNew in the above code do i get addnew to add the
> correct
> type of object (which inherits from BaseClass)