- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在开发一个名为 ListingGrid
的 DataGridView
,试图激活/停用已在内部的任何 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/
DataGridViewCheckBoxCell 未被检查。我已经像这样插入了第一列 DataGridView1.Columns.Insert(0, new DataGridViewCheckBoxC
我有一个 DataGridView 绑定(bind)到一个对象列表,我正在使用 CellFormatting 事件设置动态单元格背景颜色,如 this answer .这适用于除 DataGridVi
我有一个从 DataTable 加载数据的 DataGridView,以及一个未绑定(bind)的 DataGridViewCheckBoxCells 列。 DataGridView 中的行与单独的
我创建了一个 DataGridView 控件,其中第一列是一个复选框。当我在复选框内单击时,代码会正确执行。但是,当单击发生在单元格中而不是复选框中时,代码会正确处理复选框的状态,但不会更新复选框本身
我知道复选框的大小可以像这样改变。 checkBox1.Size = new Size(10, 10); 我想用 DataGridViewCheckBoxColumn 更改 DataGridview
我有以下 DataGridViewCheckBoxCell。问题是在编辑模式下视觉更新不会立即发生,只有当我退出它时才会发生 public class CustomDataGridViewCell :
我已经将一个数据表绑定(bind)到一个DataGridView,这个数据表有一个名为“Status”的列,它是Boolean 类型。我可以通过代码将值设置为 true 或 false 就好了。 但是
我正在开发一个名为 ListingGrid 的 DataGridView,试图激活/停用已在内部的任何 DataGridViewCheckBoxCell 上“检查”的用户DataGridViewChe
我有一个 DataGridView,其中包含 1 列定义为复选框。我不确定使用哪个事件来检查 cbo 是否已选中或未选中。我一直在使用 CellValueChanged 事件,但请注意,当我选中一个框
我正在使用 DataGridViewCheckBoxCell,但我不知道如何让 ->Value 属性“正确”工作。 for (int i = this->dgvConfigs->Rows->Count
我正在使用 .NET Windows 窗体 DataGridView,并且需要编辑 DataBound 列(绑定(bind)到 bool DataTable 列)。为此,我指定了这样的单元格模板: D
有谁知道使用 DataGridViewCheckboxCell 禁用 DataGridView 中的复选框的方法吗? 我可以将其设置为只读,并设置背景颜色,但我无法让复选框本身显示为禁用状态。有什么想
我是一名优秀的程序员,十分优秀!