双击如何检查网格复选框?

时间:2016-10-13 04:47:41

标签: c# asp.net grid

我想在双击时选中Grid上的复选框,我不想单击一下检查或取消选中。

提前致谢

1 个答案:

答案 0 :(得分:1)

CellContentDoubleClick会做你想要的。但您必须默认设置复选框ReadOnly属性 true 。我测试了这个事件,对我来说很好。让我知道这是否有助于你:

CellContentDoubleClick事件:

private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
    {
        if (dataGridView1.CurrentCell.ColumnIndex.Equals(1) && e.RowIndex != -1)
        {
            if (dataGridView1.CurrentCell != null)
                dataGridView1.CurrentCell.ReadOnly = false;
            if (dataGridView1.CurrentCell.Value != null)
                dataGridView1.CurrentCell.Value = Convert.ToInt32(dataGridView1.CurrentCell.Value) > 0 ? 0 : 1;
        }

        dataGridView1.CurrentCell.ReadOnly = true;
    }

这是我的GridView设计:

enter image description here