Is there a way to clear all of the data from the WinForm GridView? I can rebind to a new empty DataSource, but then there are no column headings. Ideally I just want to leave the columns as is and just clear the rows underneath. Is there a way to do this?
Thanks.
Dan
Thanks.
Dan
8 Answers, 1 is accepted
0
Hi Dan,
Thank you for the question.
In order to clear the RadGridView rows, you should iterate through the Rows collection and remove them one by one:
If you have additional questions, feel free to contact me.
Regards,
Nikolay
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Thank you for the question.
In order to clear the RadGridView rows, you should iterate through the Rows collection and remove them one by one:
while (this.radGridView1.Rows.Count > 0) |
{ |
this.radGridView1.Rows.RemoveAt(this.radGridView1.Rows.Count - 1); |
} |
If you have additional questions, feel free to contact me.
Regards,
Nikolay
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Atul Nisar
Top achievements
Rank 1
answered on 15 Nov 2009, 09:01 PM
This method is very inefficient. I have over 100K rows in the grid. It takes forever for this loop .
Rows.Clear() throws exception :(
0
Hello Atul Nisar,
The ADO.NET DataTable does object not support the clear operation. In order to resolve the issue, you must set AutoGenerateColumns property to false and rebind to an empty DataSource.
I hope this helps. Do not hesitate to write us back if you have additional questions.
Best wishes,
Julian Benkov
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
The ADO.NET DataTable does object not support the clear operation. In order to resolve the issue, you must set AutoGenerateColumns property to false and rebind to an empty DataSource.
this
.radGridView1.MasterGridViewTemplate.AutoGenerateColumns =
false
;
this
.radGridView1.DataSource =
new
DataTable();
//replace new DataTable() with your data source object
I hope this helps. Do not hesitate to write us back if you have additional questions.
Best wishes,
Julian Benkov
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Andrew Shyliuk
Top achievements
Rank 1
answered on 24 Mar 2010, 03:39 PM
Hello
Could I ask what prevent you to include this code into method Rows.Clear()?
Could I ask what prevent you to include this code into method Rows.Clear()?
0
Hello Andrew Shyliuk,
RadGridView supports binding to different types of objects which implement IList, IBindingList interfaces and can not contain code for specific scenarios such as the scenario of binding to a DataTable object. If you bind to an IBindingList custom business object which supports the Clear operation, RadGridView will not throw the data exception.
Best wishes,
Julian Benkov
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Thank you for the question.
RadGridView supports binding to different types of objects which implement IList, IBindingList interfaces and can not contain code for specific scenarios such as the scenario of binding to a DataTable object. If you bind to an IBindingList custom business object which supports the Clear operation, RadGridView will not throw the data exception.
Best wishes,
Julian Benkov
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Silvio Silva Junior
Top achievements
Rank 2
answered on 04 May 2010, 07:57 PM
Nice Julian!!!
Nice!
Nice!
0
Parth
Top achievements
Rank 1
answered on 15 Apr 2019, 04:39 PM
radGridView.DataSource =
Nothing
0
Hello, guys,
Setting the DataSource property to null is an appropriate solution for clearing the grid. An alternative approach is to clear the Rows and Columns collection as well:
Feel free to use this approach which suits your requirement best.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Setting the DataSource property to null is an appropriate solution for clearing the grid. An alternative approach is to clear the Rows and Columns collection as well:
this
.radGridView1.Rows.Clear();
this
.radGridView1.Columns.Clear();
Feel free to use this approach which suits your requirement best.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.