How to verify if a DataGridViewCheckBoxCell is Checked

前端 未结 7 1597
小鲜肉
小鲜肉 2021-01-11 10:45

I have bound a data table to a DataGridView, this data table has a column called \"Status\" which is of type Boolean. I can set the value to

7条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-11 11:32

    CbxCell.Value must be equal to DBNull.Value (your column can contain null values right?)

    I would check for DBNull before casting:

    if (!DBNull.Value.Equals(CbxCell.Value) && (bool)CbxCell.Value == true)
    {
        //Do stuff
    }
    else
    {
        //Do Stuff
    }
    

提交回复
热议问题