Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Collections class problem
Message
De
12/04/2006 05:00:12
 
 
À
11/04/2006 23:34:52
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Divers
Thread ID:
01112765
Message ID:
01112783
Vues:
8
Hi,

> I thought that when customer1 was created as an instance of the customer class I was creating an instance of its CustomerOrders property as well.
No. You need to create the collection instance:
   Public Class Customer
       Public CustomerName As String
       Public CustomerOrders As New Collection
    End Class
Secondly, if you want to use this:
'customerArray.Add(New Customer("Customer" + x.ToString()))
then you need a matching constructor in the Customer class:
   Sub New(ByVal s As String)
        CustomerName = s
    End Sub
HTH,
Viv


>
>I figure I must be defining the customer orders collection within the customer class incorrectly. Help would be most appreciated.

>
>    Public Class Order
>        'Public Order As String
>        Public OrderID As String
>    End Class
>
>    Public Class Customer
>        Public CustomerName As String
>        Public CustomerOrders As Collection
>    End Class
>
>    'Create a new ArrayList to hold the Customer objects
>    Private customerArray As New ArrayList()
>
>    Private Sub FillTree_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FillTree.Click
>
>        Dim x As Integer
>        For x = 0 To 999
>            'customerArray.Add(New Customer("Customer" + x.ToString()))
>            Dim newCust As New Customer()
>            newCust.CustomerName = "Customer" + x.ToString()
>            customerArray.Add(newCust)
>        Next x
>
>        'Add orders to each Customer object in the ArrayList
>        Dim customer1 As Customer
>
>        For Each customer1 In customerArray
>            Dim y As Integer
>            For y = 0 To 14
>'********************************
>                customer1.CustomerOrders.Add(New Order("Order" + y.ToString()))  'A**
>                'Dim newOrder As New Order()                    'B1**
>                'newOrder.OrderID = "Order" + y.ToString()   'B2**
>                'customer1.CustomerOrders.Add(newOrder)  'B3**
>'********************************
>            Next y
>        Next customer1
>
>        'Display a wait cursor while the TreeNoes are being created
>        Cursor.Current = New Cursor("C:\Cursors\MyWait.cur")
>
>        'Suppress repainting the TreeView until all the objects have been created
>        TreeView1.BeginUpdate()
>
>        'Clear the TreeView each time the method is called
>        TreeView1.Nodes.Clear()
>
>        'Add a root TreeNode for each Customer object in the ArrayList
>        Dim customer2 As Customer
>        For Each customer2 In customerArray
>            TreeView1.Nodes.Add(New TreeNode(customer2.CustomerName))
>
>            'Add a child TreeNode for each Order object in the current Customer object
>            Dim order1 As Order
>            For Each order1 In customer2.CustomerOrders
>                TreeView1.Nodes(customerArray.IndexOf(customer2)).Nodes.Add( _
>                New TreeNode(customer2.CustomerName + "." + order1.OrderID))
>            Next order1
>
>        Next customer2
>
>        'Reset the cursor to the default for all controls
>        Cursor.Current = System.Windows.Forms.Cursors.Default
>
>        'Begin repainting the TreeView
>        TreeView1.EndUpdate()
>
>    End Sub  'FillTree_Click'
>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform