选中 DatagridView 复选框? [英] DatagridView Checkbox Checked?

查看:60
本文介绍了选中 DatagridView 复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 datagridview 窗口表单中有一个复选框,并且有一个事件处理程序 cell_Click在单元格单击我检查 datagridview 列的复选框它显示 true 如果单元格也被选中(即复选框未选中,只有 datagrid 视图单元格被选中)并且复选框未选中.我试过列 gettype 并找出它显示的类型 DatagridViewCheckBox 但错误的检查值.???

i have a check box in a datagridview windows form and have a event handler cell_Click on cell click i check the datagridview column for a check box it shows true if the cell is selected too(that is the check box is unchecked and only the the datagrid view cell is selected) and the check box is not selected .i tried for the column gettype and found out the type it shows DatagridViewCheckBox but wrong checked values .???

推荐答案

如果我理解正确,您是说复选框值与基础数据不一致?

If I understand you correctly you are saying the checkbox value does not align with the underlying data?

这很可能是因为数据已经更新并且是脏的",例如它尚未提交到数据源.如果您添加这样的事件处理程序:

This may well be because the data has been updated and is 'dirty', e.g. it hasn't been committed to the datasource yet. If you add an event handler like this:

private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
   if (dataGridView1.CurrentCell is System.Windows.Forms.DataGridViewCheckBoxCell)
   {
      dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
   }
}

然后应该更新数据源,当您查询单元格时,您将拥有正确的复选框状态.

Then that should update the datasource and you'll have the correct checkbox state when you query the cell.

这篇关于选中 DatagridView 复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆