将对象添加到列表中的列表(嵌套列表?) [英] Adding object to list within a list (nested list?)

查看:223
本文介绍了将对象添加到列表中的列表(嵌套列表?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Winforms应用程序,它由Van类和Delivery类组成.

厢型车:

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!!

推荐答案

我认为您有一个List< van>绑定到名为VanComboBox的ComboBox-您要查找的命令是:

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)


这篇关于将对象添加到列表中的列表(嵌套列表?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆