Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Passing Arraylists of Objects to Child Form

Passing Arraylists of Objects to Child Form

Scheduled Pinned Locked Moved Visual Basic
help
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Geoff_3001
    wrote on last edited by
    #1

    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 Form Public 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

    D 1 Reply Last reply
    0
    • G Geoff_3001

      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 Form Public 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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      G 1 Reply Last reply
      0
      • D Dave Kreskowiak

        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

        G Offline
        G Offline
        Geoff_3001
        wrote on last edited by
        #3

        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

        T 1 Reply Last reply
        0
        • G Geoff_3001

          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

          T Offline
          T Offline
          TwoFaced
          wrote on last edited by
          #4

          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.

          G 1 Reply Last reply
          0
          • T TwoFaced

            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.

            G Offline
            G Offline
            Geoff_3001
            wrote on last edited by
            #5

            Ok Thanks, Makes sense wil give it a whirl.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups