Click here to Skip to main content
12,953,263 members (47,443 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
I have a winforms application which consists of a Van class and a delivery class.

Van class:

public class Van
    {
        private string VanNumber;
        public string vanNumber
        {
            get { return VanNumber; }
            set { VanNumber = value; }
        }
 
        public List<Delivery> Deliveries = new List<Delivery>();
 
        public override string ToString()
        {
            return VanNumber.ToString();
        }
 

    }



Delivery class:

public class Delivery
    {
        private string CustomerName;
        public string customerName
        {
            get { return CustomerName; }
            set { CustomerName = value; }
        }
        private string CustomerAddress;
        public string customerAddress
        {
            get { return CustomerAddress; }
            set { CustomerAddress = value; }
        }
        private DateTime ArrivalTime;
        public DateTime arrivalTime
        {
            get { return ArrivalTime; }
            set { ArrivalTime = value; }
        }
 
        public override string ToString()
        {
            return CustomerName + " " + CustomerAddress + " " + ArrivalTime.ToString();
        }
    }







I need to be able to store a list of vans, which I have done successfully using a combobox. What I now want to do, is add an instance of my delivery class to the list within a van stored in the combobox. I have a button on my main form(contains combobox) which links to form for adding deliveries. Ideally, i'd like to be able to highlight a van in the combobox and add a delivery via the 'add delivery' form. I just have no idea how to do this!

Any help is greatly appreciated!!
Posted 27-Nov-12 22:45pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

I assume you have a List<van> bound to ComboBox called, say, VanComboBox - the command you are looking for is:

((Van)VanComboBox.SelectedItem).Deliveries.Add(DeliveryItem)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
Jochen Arndt 1,975
ppolymorphe 1,920


Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 28 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100