标签:
对于dataGridView,设置数据源为一个List集合时,修改了List集合以后即使重新设置数据源界面也不会刷新。
注:如果先设置DataSource=null;可以重新加载,但是界面设计器里面设置的列名称,表头全部消失。
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 }); } }
Winform DataGridView修改数据源界面不刷新问题
标签:
原文地址:http://www.cnblogs.com/shya/p/4413462.html