How to check if dataGridView checkBox is checked?

前端 未结 6 1805
猫巷女王i
猫巷女王i 2021-01-04 09:13

I\'m new to programming and C# language. I got stuck, please help. So I have written this code (c# Visual Studio 2012):

private void button2_Click(object sen         


        
6条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-04 09:48

    You should use Convert.ToBoolean() to check if dataGridView checkBox is checked.

    private void button2_Click(object sender, EventArgs e)
    {
        foreach (DataGridViewRow row in dataGridView1.Rows)
        {
             if (Convert.ToBoolean(row.Cells[1].Value))
             {
                  // what you want to do
             }
        }
    }
    

提交回复
热议问题