c# - Get DataTable from DataGridView respecting filters and sorting -


i have system.windows.forms.datagridview filled data. i'm using code this:

system.data.datatable datatable1; system.windows.forms.bindingsource bindingsource1; system.windows.forms.datagridview datagridview1;  // (...)  bindingsource1.datasource = datatable1;  datagridview1.datasource = bindingsource1;  bindingsource1.filter = "some filter here"; 

what need recover data in datagridview1. don't need complicated. datagridview1 readonly thing need respect order , filter used, , export data datatable.

anyone can me?

if understand correctly, need filtered rows displaying in datagridview datatable. can make use of datatable.defaultview property purpose includes filters.

try this

bindingsource bs = (bindingsource)datagridview1.datasource; datatable table = (datatable)bs.datasource; datatable filtered = table.defaultview.totable();// here filtered datatable 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -