Search code examples
c#gridviewdatagridviewdevexpressdevexpress-windows-ui

Get filtered rows from devexpress gridview c#


I am using devexpress GridView in my c# application. So I initialize my GridView like this:

gridControl.DataSource = new BindingList<ViewDomainClass.MaterialOffice.DAViewMTO>(_materialRepository.ViewMTOByDetail())

The output value of that is a List<DAViewMTO>. So my user is able to filter the data in GridView and I need just the data that my users filtered.

So I need to move these data (Filtered) to another list of type List<DAViewMTO>

How can I do that?


Solution

  • Use this :

     public static List<T> GetFilteredData<T>(ColumnView view)
            {
                List<T> resp = new List<T>();
                for (int i = 0; i < view.DataRowCount; i++)
                    resp.Add((T)view.GetRow(i));
    
                return resp;
            }
    

    And call like this :

    ColumnView View = gridControl.MainView as ColumnView;
        List<DAViewMTO> mydata= GetFilteredData<DAViewMTO>(View).ToList();