datagridview 绑定 datatable

时间:2014-07-06 22:02:21   收藏:0   阅读:385

if (dt != null)
{
DataGridViewColumn dgvc = null;
this.dataGridView1.DataSource = null;
this.dataGridView1.Columns.Clear();
foreach (DataColumn dc in dt.Columns)
{
dgvc = new DataGridViewColumn();
dgvc.Name = dc.ColumnName;
dgvc.HeaderText = dc.ColumnName;
dgvc.DataPropertyName = dc.ColumnName;
dgvc.CellTemplate = new DataGridViewTextBoxCell();
dgvc.Resizable = DataGridViewTriState.True;
dgvc.SortMode = DataGridViewColumnSortMode.Automatic;
this.dataGridView1.Columns.Add(dgvc);
}
this.dataGridView1.AutoGenerateColumns = false;
this.dataGridView1.DataSource = dt;

}

datagridview 绑定 datatable,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!