如何判断DataGridViewCheckBoxCell被选中

 

假设DataGridView为dgv

1、判断DataGridViewCheckBoxCell是否被选中

  DataGridViewCheckBoxCell chkcell = dgv[1,0] as DataGridViewCheckBoxCell;

  bool IsChecked = Convert.ToBoolean(chkcell.EditingCellFormattedValue);

  //注意此处获取DataGridViewCheckBoxCell是否选中的值,在DataGridView的CellContentClick事件(或者其他DataGridView事件)中应该取chkcell.EditingCellFormattedValue,而在非DataGridView事件比如说按钮Button的Click事件中,直接取chkcell.Value就可以了

  if(IsChecked)

  {

    //当前CheckBoxCell被选中

  }

 

2、往DataGridViewComboBoxCell中添加不同的数据源

  

  //开始编辑单元格时填充枚举项(人员属性的枚举)
        private void dgvPersonProperty_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            try
            {
                Wag_PersonPropertyExt.Wag_PersonPropertyExtRow pper = dgvPersonProperty.Rows[e.RowIndex].Tag as Wag_PersonPropertyExt.Wag_PersonPropertyExtRow;

                Wag_PersonPropertyCode dsPersonPropertyCode = WageItemDistibutionMethod.GetPersonPropertyCodeByPropertyId(pper.PropertyId.ToString());

                DataGridViewComboBoxCell cmb = dgvPersonProperty[e.ColumnIndex, e.RowIndex] as DataGridViewComboBoxCell;
                cmb.DataSource = dsPersonPropertyCode._Wag_PersonPropertyCode;
                cmb.DisplayMember = "CodeName";
                cmb.ValueMember = "PropertyCodeId";
            }
            catch (System.Exception ex)
            {
                MsgHelper.WarnMSG(ex.Message);
            }
        }

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值