简体   繁体   English

具有DataGrid行的WPF循环

[英]WPF Loop with DataGrid Rows

First: this is my code at the moment 第一:这是我目前的代码

    class Plan
    {
        public string Linie { get; set; }
        public string Kurs { get; set; }
        public string Abfahrt { get; set; }
        public string Von { get; set; }
        public string Nach { get; set; }
        public string Ankunft { get; set; }
        public string Pause { get; set; }

        public Plan(string Linie, string Kurs, string Abfahrt, string Von, string Nach, string Ankunft, string Pause)
        {
            this.Linie = Linie;
            this.Kurs = Kurs;
            this.Abfahrt = Abfahrt;
            this.Von = Von;
            this.Nach = Nach;
            this.Ankunft = Ankunft;
            this.Pause = Pause;
        }

    private System.Collections.ObjectModel.ObservableCollection<Plan> _items = new System.Collections.ObjectModel.ObservableCollection<Plan>();
    Plan.ItemsSource = _items;

So: I want a loop, that do something foreach row. 所以:我想要一个循环,为每个行做一些事情。 So, as example: A loop that show a MessageBox, which contains each cell (I mean [as example] the Linie of the seleceted row an so on) 因此,例如:一个显示MessageBox的循环,其中包含每个单元格(我的意思是[作为示例]被选中行的Linie等)

I am happy about each answer! 每个答案我都很高兴! Thank a lot! 非常感谢!

You could make a list of Plan . 您可以列出Plan

To create list: 创建列表:

List<Plan> ListPlan=new List<Plan>();
ListPlan.Add(new Plan("","","",...);

To read list: 阅读清单:

foreach (Plan p in ListPlan)
{
MessageBox.Show(p.Linie)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM