如何能在C#中的DataGridView我清楚行? [英] How can I clear rows in DataGridView with C#?
问题描述
在这一行下面的错误。
datagridview1.Rows.Clear()
但此行给出了错误:
不能清除该列表。
块引用>解决方案我也有类似的问题时,我尝试清除DataGridView的数据源我曾它绑定到一个DataTable后:
DataTable的DT = ...; // 填充
datagridview1.DataSource = DT;当我尝试用下面的code后清除它的行:
datagridview1.DataSource = NULL
我得到这个错误:
错误:未将对象引用设置到对象的实例
该对象引用错误的问题已经解决了<一个href=\"http://stackoverflow.com/questions/7867136/datagridview-datasource-null-error-object-reference-not-set-to-an-instance-o\">here.但我管理这个code,解决我自己的问题(清算行的DataGridView):
DataTable的DT =(数据表)datagridview1.DataSource;
如果(DT!= NULL)
DT.Clear();我知道,这个问题被问了一个很长的时间以前,但我希望我的解决方案能解决问题的人。
Following Error in this line.
datagridview1.Rows.Clear()
but this line gives error:
Cannot clear this list.
解决方案I also had similiar problem when I try to clear DataSource of a DataGridView after I had binded it to a DataTable with:
DataTable DT = ... ; // fill it datagridview1.DataSource = DT;
when I try to clear it's rows later with the following code:
datagridview1.DataSource = null
I get this error:
ERROR: Object reference not set to an instance of an object
This object reference ERROR problem already solved in here. But I managed to solve my own problem (clearing DataGridView rows) with this code:
DataTable DT = (DataTable)datagridview1.DataSource; if (DT != null) DT.Clear();
I know that this question was asked a very long time ago, but I hope my solution would solve someone problems.
这篇关于如何能在C#中的DataGridView我清楚行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!