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

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

错误代码:blog

/*禁止自动建立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];
}ip

执行后:it

增长正确代码:io

/*TestDynamic属性*/test

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


/*TestSynch属性*/im

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

运行结果:数据

相关文章
相关标签/搜索