【发布时间】:2017-06-12 05:54:34
【问题描述】:
我有一个绑定到列表的DataGirdView。
我想通过DataGridViewCheckBoxCell 在某个单元格上添加CheckBox,但我的datagridview 上没有显示控制器。以下是我的代码:
class ColumnNames
{
public string Check { get; set; }
public string Index { get; set; }
public string SubIndex { get; set; }
public string Name { get; set; }
public string Value { get; set; }
public ColumnNames(
string Check,
string Index,
string SubIndex,
string Name,
string Value
)
{
this.Check = Check;
this.Index = Index;
this.SubIndex = SubIndex;
this.Name = Name;
this.Value = Value;
}
}
itemsList.Add(new ColumnNames(Check, Index, SubIndex, Name, DataType));
datagridview.DataSource = itemsList;
datagridview.Rows[0].ReadOnly = true;
datagridview.Rows[0].Cells[0] = new DataGridViewCheckBoxCell();
datagridview.Rows[0].Cells[0].Value = false;
当我运行此代码时,我只在单元格 [0] 上得到字符串“假”。 我已经使用断点监视这个单元格,这个单元格是 "Datagirdviewcheckboxcell" ,但没有复选框控制器。 我怎么解决这个问题?谢谢!
【问题讨论】:
-
因为您将列属性设置为只读,请尝试删除
datagridview.Rows[0].ReadOnly = true;行 -
我可能是错的,但我相信该复选框只能针对布尔属性正确操作。你对班级有控制权吗?你可以添加一个像
public bool CheckBool { get { return bool.Parse(this.Check); } set { this.Check = value.ToString(); } }这样的属性然后绑定到它吗?
标签: c# checkbox datagridview