最初的界面图如图1-1(全选框ID: cb_checkall  DEV控件名称:gcCon ):

DEV控件中GridView中的复选框与CheckBox实现联动的全选功能

要实现的功能如下图(1-2  1-3  1-4)及代码所示:

DEV控件中GridView中的复选框与CheckBox实现联动的全选功能图1-2

 

DEV控件中GridView中的复选框与CheckBox实现联动的全选功能图1-3

 

DEV控件中GridView中的复选框与CheckBox实现联动的全选功能图1-4

 

O(∩_∩)O哈哈~

不要着急哦,看清要实现的功能后我们来上代码啦!!

 1     //全局变量 0:表格中的数据没有全部选中 1:表格中的数据全部选中
 2     public int iCheckAll=0;
 3     private void repositoryItemCheckEdit1_CheckedChanged(object sender, EventArgs e)
 4         {
 5             CheckEdit chkCheck = (sender as CheckEdit);
 6             DataRow dr = gridView1.GetFocusedDataRow();
 7             if (chkCheck.CheckState == CheckState.Checked)
 8             {
 9                 dr["IS_CHECK"] = "1";
10             }
11             else
12             {
13                 dr["IS_CHECK"] = "0";
14 
15             }
16 
17             //增加全部选择时,全选按钮应该勾选上
18             DataTable dt = gcCon.DataSource as DataTable;
19            
20             //判断如果GridView中按钮都全选了,把全选按钮也设置为选中状态 
21             DataRow[] drTemp = dt.Select("IS_CHECK=0 OR IS_CHECK IS NULL");
22             if (drTemp.Length > 0)
23             {
24                 //没有全部选中
25                 iCheckAll = 0;
26                 cb_checkall.CheckState = CheckState.Unchecked;
27             }
28             else
29             {
30                 iCheckAll = 1;
31                 cb_checkall.CheckState = CheckState.Checked;
32             }
33            
34         
35 
36         }
表格中复选框的CheckedChanged事件

相关文章:

  • 2022-02-04
  • 2021-11-23
  • 2021-10-10
  • 2022-12-23
  • 2021-06-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-01
  • 2021-05-23
  • 2021-07-05
相关资源
相似解决方案