【发布时间】:2012-11-29 18:43:25
【问题描述】:
我正在开发一个名为ListingGrid 的DataGridView,试图激活/停用已在DataGridViewCheckBoxColumn 内的任何DataGridViewCheckBoxCell 上“检查”的用户。
这就是我尝试这样做的方式:
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 然后比较它,这会抛出一个无效的强制转换异常。
【问题讨论】:
-
也许与这个问题并不完全相关,但这可能会有所帮助:stackoverflow.com/a/48465766/5750078