我正在以编程方式更新我的WinForm DataGridView
问题是,DataGridViewCheckBoxCell没有更新!
我是谷歌,它的接缝就像了解案例,但无论我尝试了什么,都没有帮助。
private void InitializeFunctionsDataGrid()
{
System.Data.DataSet ds = func.GetFunctions();
this.FunctionsDataGrid.DataSource = ds.Tables[0];
this.FunctionsDataGrid.Columns["FunctionId"].Visible = false;
this.FunctionsDataGrid.Columns["DESCRIPTION"].Width = 370;
DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
column.Name = "enable";
column.HeaderText = "enable";
column.FalseValue = 0;
column.TrueValue = 1;
FunctionsDataGrid.Columns.Add(column);
foreach(DataGridViewRow row in FunctionsDataGrid.Rows)
{
(( DataGridViewCheckBoxCell)row.Cells["enable"]).Value = 1;
}
FunctionsDataGrid.CurrentCell = null;
}发布于 2014-04-08 23:43:37
好的,对我来说,最简单的方法就是使用数据源。我已经将该列添加到DataTable中,并将其填充为数据。最后一件事是this.FunctionsDataGrid.DataSource = ds.Tables;
发布于 2014-04-08 05:57:08
enable是一个未绑定的列。这意味着您需要自己提供单元格值。
可以将VirtualMode属性设置为true并处理CellValueNeeded事件。
如果要启用用户检查单元格,则需要处理CellValuePushed事件。作为DataGridView的一部分的DataGridView常见问题示例有一个未绑定复选框列和数据库列的特定示例。
https://stackoverflow.com/questions/22928106
复制相似问题