如何为WinGrid表格控件中列表头添加checkbox

作者:控件中国网   出处:控件中国网   2015-08-25 10:07:48   阅读:7

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);
         
        }
运行效果:
Wingrid_Displaying_Checkbox_in_Column_header.png

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat