简体   繁体   English

Datagridview复选框列的值

[英]Datagridview checkbox column's value

I have a DataGridView with a checkbox column. 我有一个带复选框列的DataGridView。 I want to capture the value of the checkbox immediately when user changes it by clicking. 当用户通过单击更改复选框时,我想立即捕获复选框的值。 I tried several events ( CellValueChanged , CellClicked , CurrentCellDirtyStateChanged etc.) but nothing worked. 我尝试了几个事件( CellValueChangedCellClickedCurrentCellDirtyStateChanged等),但没有任何效果。

This is my code: 这是我的代码:

If dgvIDsTBC.CurrentRow.Cells(2).Value = True Then
    MsgBox("True")
End If

Please help 请帮忙

Hope this helps 希望这可以帮助

void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
     if (e.ColumnIndex == 3)
        MessageBox.Show(dataGridView1[e.ColumnIndex, e.RowIndex].FormattedValue.ToString());
}

This i presume you would have done, now the catch is unless you move out of the cell the grid considers you are still editing ,So Add this part 这个我认为你会做的,现在捕获是除非你移出网格认为你仍在编辑的单元格,所以添加这个部分

void dataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
{
    if (e.ColumnIndex == 3)
       dataGridView1.EndEdit();
}

This should be fine for you, 3 is the checkbox column you intend it to work for 这应该没问题,3是你想要它的复选框列

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM