开发者

Convert Filtered DataGridView To DataTable in C#

开发者 https://www.devze.com 2023-02-16 21:31 出处:网络
I use BindingSource.Filter to f开发者_开发技巧ilter data shown in a DataGridView.How can I convert filtered data in a DataGridView to a DataTable??A BindingSource actually uses the DefaultView of the

I use BindingSource.Filter to f开发者_开发技巧ilter data shown in a DataGridView. How can I convert filtered data in a DataGridView to a DataTable??


A BindingSource actually uses the DefaultView of the source DataTable. When you set BindingSource.Filter, it sets the RowFilter property on the table's DefaultView, so you just need to call ToTable on the DefaultView:

DataTable filtered = sourceDataTable.DefaultView.ToTable();

(I'm assuming the DataSource of the BindingSource is a DataTable; if it's not the case, this solution won't work)


You can always convert datagridview data to datatable by using custom function that iterates thru datagridview row and columns and dynamically generates datatable derived from the structure of an existing datagridview.. Here it is what i have found:.

How to convert Datagridview Data to Datatable

0

精彩评论

暂无评论...
验证码 换一张
取 消