Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a winforms application which consists of a Van class and a delivery class.

Van class:

C#
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:

C#
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

1 solution

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

C#
((Van)VanComboBox.SelectedItem).Deliveries.Add(DeliveryItem)
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900