Get DataTable from DataGridView respecting filters and sorting

前端 未结 1 2027
南笙
南笙 2021-01-15 02:31

I have a System.Windows.Forms.DataGridView filled with data. I\'m using some code like this:

System.Data.DataTable dataTable1;
System.Windows.Fo         


        
相关标签:
1条回答
  • 2021-01-15 03:27

    If I understand you correctly, you need the filtered rows displaying in DataGridView as DataTable. You can make use of DataTable.DefaultView property for this purpose which includes all the filters.

    Try this

    BindingSource bs = (BindingSource)dataGridView1.DataSource;
    DataTable table = (DataTable)bs.DataSource;
    DataTable filtered = table.DefaultView.ToTable();// here we get filtered datatable
    
    0 讨论(0)
提交回复
热议问题