【发布时间】:2014-06-20 15:38:57
【问题描述】:
我有一个用LINQ 创建的DataView,连接到DataGridView。当我更改DataGridView 中的值时,LINQ 表达式会立即执行并更改我的DataView 中的结果。
有没有办法"disconnect" the DataGridView from the LINQ script 来抑制 DataView 中的更改?
void MyFunc()
{
DataGridView myGrid;
DataTable myTable;
// filling the table
// assigning the table to the grid
myGrid.DataSource = myTable;
// filtering DataTable with LINQ
var filteredRows = (from DataRow in myTable.AsEnumerable()
where (...)
select (row));
// assigning the result to the DataGrid
myGrid.DataSource = filteredRows.AsDataView();
...
}
【问题讨论】:
-
你的意思是:推迟更新?您实际上想更新它们,但不是现在,不是吗?
-
试试
CopyToDataTable而不是AsDataView -
是的,我想推迟更新@Daniel:我必须删除行。当我使用表的副本时,我必须手动删除原始表中的行。
标签: c# linq datagridview datatable