C# Winform中DataGridView绑定后DataGridViewCheckBoxColumn无法显示的问题

在控件DataGridView绑定数据源后,发现DataGridViewCheckBoxColumn不能显示当前的check值。经过一番努力,现将完整代码奉献出来,仅供参考。

错误代码:

/*禁止自动创建Column*/
this.dgvTestType.AutoGenerateColumns = false;
/*设置binding 属性值*/
this.dgvTestType.Columns[0].DataPropertyName ="Id";
this.dgvTestType.Columns[1].DataPropertyName = "TestType";
this.dgvTestType.Columns[2].DataPropertyName = "Name";
this.dgvTestType.Columns[3].DataPropertyName ="TestDynamic"; //Check列
this.dgvTestType.Columns[4].DataPropertyName ="TestSynch";//Check列
this.dgvTestType.Columns[5].DataPropertyName = "Description";

/*获取数据源*/
DataSet ds = SqliteSingleModel.Instance.ReadMethod("select [Id],[TestType],[Name],[TestDynamic],[TestSynch],[Description] from config_testtype order by TestType");
/*binding 数据源*/
if (ds.Tables[0] != null)
{
this.dgvTestType.DataSource = ds.Tables[0];
}

执行后:

增加正确代码:

/*TestDynamic属性*/

DataGridViewCheckBoxColumn checkboxDynamic = this.dgvTestType.Columns[3] as DataGridViewCheckBoxColumn;
checkboxDynamic.TrueValue = "True";
checkboxDynamic.FalseValue = "False";


/*TestSynch属性*/

DataGridViewCheckBoxColumn checkboxSynch = this.dgvTestType.Columns[4] as DataGridViewCheckBoxColumn;
checkboxSynch.TrueValue = "True";
checkboxSynch.FalseValue = "False";

运行结果:

 

posted @ 2016-12-20 14:55  ldldavid  阅读(5296)  评论(0编辑  收藏  举报