gpt4 book ai didi

c# - 从 DataGridViewCheckBoxCell 获取值

转载 作者:太空狗 更新时间:2023-10-29 22:10:56 24 4
gpt4 key购买 nike

我正在开发一个名为 ListingGridDataGridView,试图激活/停用已在内部的任何 DataGridViewCheckBoxCell 上“检查”的用户DataGridViewCheckBoxColumn

这就是我尝试这样做的方式:

foreach (DataGridViewRow roow in ListingGrid.Rows)
{
if ((bool)roow.Cells[0].Value == true)
{
if (ListingGrid[3, roow.Index].Value.ToString() == "True")
{
aStudent = new Student();
aStudent.UserName = ListingGrid.Rows[roow.Index].Cells[2].Value.ToString();
aStudent.State = true;
studentList.Add(aStudent);

}
}
}

据我所知,当您检查 DataGridViewCheckBoxCell 时,单元格的值为 true 对吗?但它不允许我将值转换为 bool 然后比较它,抛出一个无效的转换异常。

最佳答案

尝试:

DataGridViewCheckBoxCell chkchecking = roow.Cells[0] as DataGridViewCheckBoxCell;

if (Convert.ToBoolean(chkchecking.Value) == true)
{
}

DataGridViewCheckBoxCell chkchecking = roow.Cells[0] as DataGridViewCheckBoxCell;

if ((bool)chkchecking.Value == true)
{
}

关于c# - 从 DataGridViewCheckBoxCell 获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13632536/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com