I have a custom object, InvestmentPriceCollection, that is a collection of InvestmentPrice. In a Windows form, I have code that successfully creates a new InvestmentPriceCollection, and by iterating through a gridview, creates new instances of InvestmentPrice (Dim inv as New InvestmentPrice), appending each to InvestmentPriceCollection. This all works great. Naturally, I can't be content with that :-)
Rather than storing this iteration routine (let's call it LoadFromGridview) at the form level, I'd like to make it more available across the application, and incorporate it into InvestmentPriceCollection. Here's where I run into a problem.
When I create my public function LoadFromGridview in InvestmentPriceCollection, and attempt to define a new InvestmentPrice (Dim inv as New InvestmentPrice), I received the following error:
'New' cannot be used on a type parameter that does not have a 'New' constraint.
I resolved this error by changing the collection class declaration from Public Class InvestmentPriceCollection(Of InvestmentPrice) to:
Public Class InvestmentPriceCollection(Of InvestmentPrice As {New})
But now I'm having problems assigning values to the properties of InvestmentPrice (assume dateparameter is a valid date).
Dim inv as New InvestmentPrice
inv.AsOfDate = dateparameter
The error states that 'AsOfDate' is not a member of 'InvestmentPrice' - but it is! And I've been able to refer to it in the aforementioned form code.
Am I going about this in the wrong way? Will I be able to include LoadFromGridview in the InvestmentPriceCollection object? Is there a better or different way to store it elsewhere in the app?
Form1.vb -
Open in new window
Form1.Designer.vb -Open in new window
Produces the following output --saige-