如何检查dataGridView复选框是否已选中? [英] How to check if dataGridView checkBox is checked?

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

问题描述

我是编程和C#语言的新手.我被卡住了,请帮忙.所以我已经编写了这段代码(c#Visual Studio 2012):

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 sender, EventArgs e)
{
    foreach (DataGridViewRow row in dataGridView1.Rows)
    {
         if (row.Cells[1].Value == true)
         {
              // what I want to do
         }
    }
}

所以我收到以下错误:

运算符'=='不能应用于类型为'object'和'bool'的操作数.

推荐答案

您应使用 Convert.ToBoolean()来检查dataGridView复选框是否已选中.

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
         }
    }
}

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

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