generics - creating a new item

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i am new to generics so...
if i have say

dim MySecondList as new BindingList (Of MyFirstThing)
dim MyFirstList as new BindingList (Of MySecondThing)

how can i instantiate a new item withing the list without knowing what Type
to create?
so i might have

sub Dostuff( bl as BindingList)
'create a new item in the bindinglist
i want to be able to say something like
bl.AddNewItem
and have the binding list instantiate the right sort of item and add it
to the list
so that if the list is MyFirstList it adds a new MyFirstThing
but if it is a MySecondList it adds a new MySecondThing

end sub

how do i do that?

thanks guy
 
'create a new item in the bindinglist
i want to be able to say something like
bl.AddNewItem

BindingList has an AddNew method, is that what you're looking for?


Mattias
 
Dim oFirstThing As Object
Dim oSecondThing As Object

oFirstThing = New MyFirstThing
oSecondThing = New MySecondThing

If TypeOf oFirstThing Is MyFirstThing Then
MyFirstList.Add(oFirstThing)

If TypeOf oSecondThing Is MySecondThing Then
MySecondList.Add(oSecondThing)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top