Exemplo n.º 1
0
        public void bindDatagridview()
        {
            List <KuCun> list = cal.SelectKC();
            DataTable    dt   = new DataTable();

            dt.Columns.Add("Id", typeof(int));
            for (int i = 0; i < dataGridView1.Columns.Count; i++)
            {
                if (!dataGridView1.Columns[i].HeaderCell.Value.ToString().Equals("Id"))
                {
                    dt.Columns.Add(dataGridView1.Columns[i].HeaderCell.Value.ToString(), typeof(String));
                }
            }
            foreach (KuCun s in list)
            {
                dt.Rows.Add(s.Id, s.PingMing, s.HuoHao, s.SeHao, s.ShuLiang, s.GongHuoFang, s.CunFangDI);
            }
            dataGridView1.DataSource = dt;
        }