datagridview数据源WinformDataGridView修改数据源界⾯不刷新问题
对于dataGridView,设置数据源为⼀个List集合时,修改了List集合以后即使重新设置数据源界⾯也不会刷新。
注:如果先设置DataSource=null;可以重新加载,但是界⾯设计器⾥⾯设置的列名称,表头全部消失。
1. 设置数据源为DataTable
2. 使⽤Rows.Add⽅法添加⼦项,需要重新加载数据时,先⽤Rows.Clear清理所有⼦项。
private void BindData()
{
this.dgvMappings.ColumnCount = 5;
this.dgvMappings.Columns[0].HeaderText = "数据源表名称";
this.dgvMappings.Columns[1].HeaderText = "数据源表主键";
this.dgvMappings.Columns[2].HeaderText = "⽬标表名称";
this.dgvMappings.Columns[3].HeaderText = "数据源查询字段";
this.dgvMappings.Columns[4].HeaderText = "⽬标表插⼊字段";
this.dgvMappings.Columns[0].Name = "SourceTableName";
this.dgvMappings.Columns[1].Name = "SourceTablePrimaryKey";
this.dgvMappings.Columns[2].Name = "TargetTableName";
this.dgvMappings.Columns[3].Name = "SourceFields";
this.dgvMappings.Columns[4].Name = "TargetFields";
this.dgvMappings.Columns[0].Width = 100;
this.dgvMappings.Columns[1].Width = 100;
this.dgvMappings.Columns[2].Width = 100;
this.dgvMappings.Columns[3].Width = 215;
this.dgvMappings.Columns[4].Width = 215;
this.dgvMappings.Rows.Clear();
foreach(var map in settings.TableMapings)
{
this.dgvMappings.Rows.Add(new string[] { map.SourceTableName,map.SourceTablePrimaryKey,map.TargetTableName,map.SourceFields,map.TargetFields }); }
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论