WinGrid是一款功能强大的表格控件,包含在界面套包infragistics for Windows Forms里,WinGrid支持对某一列所有单元格值进行选择,这篇文章主要介绍如何为表格中,某一列的列头上加上checkbox,然后选择该复选框后所有该列的值就被选取了,具体如下:
//Display a checkbox in the column header, where column's data type isBoolean,DefaultableBoolean, or Nullable Boolean.
this.ultraGrid1.DisplayLayout. Bands[0].Columns["IsActive"].Header.CheckBoxVisibility = HeaderCheckBoxVisibility.WhenUsingCheckEditor;
//Aligns the Header checkbox to the right of the Header caption
this.ultraGrid1.DisplayLayout.Bands[0].Columns["IsActive"].Header.CheckBoxAlignment = HeaderCheckBoxAlignment.Right;
//The checkbox and the cell values are kept in synch to affect only the RowsCollection
this.ultraGrid1.DisplayLayout.Bands[0].Columns["IsActive"].Header.CheckBoxSynchronization = HeaderCheckBoxSynchronization.RowsCollection;
当选中状态改变时,可以通过 BeforeHeaderCheckStateChecked和the AfterHeaderCheckStateChecked事件进行处理
private void ultraGrid2_AfterHeaderCheckStateChanged(object sender, AfterHeaderCheckStateChangedEventArgs e)
{
CheckState currentCheckState = e.Column.GetHeaderCheckedState(e.Rows);
}
运行效果: