Essential Grid是一款可视化编辑、更新、保存数据的表格控件,支持多种表格操作、超过15种单元格类型,支持多种.NET下常用的数据源,该产品包含在
Essential Studio for Windows Forms界面套包产品。这篇文章主要介绍怎么在表格控件Essential Grid中为表格中的某列头添加一个复选框,以便进行数据的选择。
当放置一个CheckBox在GridControl中时需要设置CellType为CheckBox,并且为CheckedValue和UncheckedValue设置一个字符串值,当复选框被选中时CheckBoxClick事件被触发。具体的使用方法可以参考下面的部份代码:
private string CheckBoxValue;
private void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
//Checks for a row header.
if(e.ColIndex > 0 && e.RowIndex == 0)
{
int colIndex1 = this.gridDataBoundGrid1.Binder.NameToColIndex("Column2");
if(colIndex1 == e.ColIndex)
{
e.Style.Description = "Check";
//Displays CellValue.
e.Style.CellValue = CheckBoxValue;
e.Style.CellValueType = typeof(string);
//Determines CheckBoxOptions Values.
e.Style.CheckBoxOptions = new GridCheckBoxCellInfo(true.ToString(), false.ToString(), "", true);
//Sets up CheckBox control in the header.
e.Style.CellType = "CheckBox";
e.Style.CellAppearance = GridCellAppearance.Raised;
e.Style.Enabled = true;
}
}
}
private void Model_SaveCellInfo(object sender, GridSaveCellInfoEventArgs e)
{
if(e.ColIndex > 0 && e.RowIndex == 0)
{
int colIndex1 = this.gridDataBoundGrid1.Binder.NameToColIndex("Column2");
if(colIndex1 == e.ColIndex)
{
//Saves the changes that are made in the Cell Value.
if(e.Style.CellValue != null)
CheckBoxValue = (string)e.Style.CellValue;
}
}
}