• DataGridView窗体之间的传递


     用datatable处理DataGridView比较方便,但是今天在帮朋友做时,没用数据库,用的List集合去做了,结果发现List集合不能转为datatable

    private void button1_Click(object sender, EventArgs e)
            {
               
                DataTable dt = new DataTable();
                DataTable dt2 = new DataTable();
                dt2.Columns.Add("Name");
                dt2.Columns.Add("Age");
                for (int i = 0; i < dataGridView1.SelectedRows.Count; i++)
                {
                    DataRow dr = dt2.NewRow();
                    dr["Name"] = dataGridView1.SelectedRows[i].Cells[0].Value;
                    dr["Age"] = dataGridView1.SelectedRows[i].Cells[1].Value;
                    dt2.Rows.Add(dr);
                }
                Form2 fr = new Form2(dt2);
                fr.Show();
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                List<person> list1 = new List<person>
                {
                    new person{Name="123",Age=12},
                    new person{Name="234",Age=12}
                };
                dataGridView1.DataSource = list1;
            }
        }
    }

  • 相关阅读:
    网络爬虫之第一章网络请求
    rabbitmq学习(一) —— 安装篇
    jenkins自动构建部署
    httpclient初步封装
    谈谈“拥抱变化”
    mongo对分组数据进行排序
    困兽
    go语言——goland中项目目录及编译说明
    最长回文子串
    java中关于锁知识的整理
  • 原文地址:https://www.cnblogs.com/wuyuetian/p/3898036.html
Copyright © 2020-2023  润新知