.net第三方控件developer express,竟然发现里面的模板列RepositoryItemCheckEdit默认的状态和单选钮一样,虽然我们有时候也很需要这样的功能,但是有时候我们也要有复选按钮的功能
1.将要设置的列,设一个模板列为RepositoryItemCheckEdit1
2.绑定要显示的字段,若没有可以自己构造一个空列,如:select '1' as 新列 ,T.*,from table1 T,也可设为'True'或者'Yes',视个人情况而定
3.设置事件:repositoryItemCheckEdit1_QueryCheckStateByValue
4.代码示例如下:
4.1 //根据绑定的值显示选择状态
private void repositoryItemCheckEdit1_QueryCheckStateByValue(object sender, DevExpress.XtraEditors.Controls.QueryCheckStateByValueEventArgs e)
{
string val = "";
if (e.Value != null)
{
val = e.Value.ToString();
}
else
{
val = "False";//默认为不选
}
switch (val)
{
case "True":
case "Yes":
case "1":
e.CheckState = CheckState.Checked;
break;
case "False":
case "No":
case "0":
e.CheckState = CheckState.Unchecked;
break;
default:
e.CheckState = CheckState.Checked;
break;
}
e.Handled = true;
}
4.2 //由选择状态改变绑定列的值
private void repositoryItemCheckEdit1_QueryValueByCheckState(object sender, DevExpress.XtraEditors.Controls.QueryValueByCheckStateEventArgs e)
{
if (e.CheckState == CheckState.Checked)
{
gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "绑定列", 1);
}
else
{
gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "绑定列", 0);
}
}