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
精彩评论