Passing Arraylists of Objects to Child Form
-
Hi, I am trying to pass an arrylist to a child form as below. I get an error saying not posible to cast Stockobj to Stockobj. If I change the arraylist to contain strings not objs it works fine. Any clues welcome Thanks Parent Form
Public Class Stockobj Public Id As Integer Public Name As String Public Plex As String End Class Private WithEvents MixForm As MixForm Dim StockNameList As New ArrayList 'Code Populates StockNameList Me.MixForm = New MixForm(StockNameList) Me.MixForm.Show()
Child FormPublic Class Stockobj Public Id As Integer Public Name As String Public Plex As String End Class Dim StockNameList As New ArrayList Public Sub New(ByVal StockAliquots As ArrayList) InitializeComponent() End Sub
-
Hi, I am trying to pass an arrylist to a child form as below. I get an error saying not posible to cast Stockobj to Stockobj. If I change the arraylist to contain strings not objs it works fine. Any clues welcome Thanks Parent Form
Public Class Stockobj Public Id As Integer Public Name As String Public Plex As String End Class Private WithEvents MixForm As MixForm Dim StockNameList As New ArrayList 'Code Populates StockNameList Me.MixForm = New MixForm(StockNameList) Me.MixForm.Show()
Child FormPublic Class Stockobj Public Id As Integer Public Name As String Public Plex As String End Class Dim StockNameList As New ArrayList Public Sub New(ByVal StockAliquots As ArrayList) InitializeComponent() End Sub
You can't have two classes with the same name in the same assembly. You're defining Stockobj twice...
Dave Kreskowiak Microsoft MVP - Visual Basic
-
You can't have two classes with the same name in the same assembly. You're defining Stockobj twice...
Dave Kreskowiak Microsoft MVP - Visual Basic
Dave I have renamed both destination obj and arraylist i still get the following error Unable to cast object of type StockObj to NewStockObj. Excepy for the name they are indentical. Cheers
-
Dave I have renamed both destination obj and arraylist i still get the following error Unable to cast object of type StockObj to NewStockObj. Excepy for the name they are indentical. Cheers
-
They aren't identical because they are completly different objects Having the same properties and methods doesn't make two objects the same. What you need to do is define StockObj once publicly so that both forms know about it.
Ok Thanks, Makes sense wil give it a whirl.