1

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?

Ehsan Akbar
  • 6,977
  • 19
  • 96
  • 180
  • Hi @Ehsan, Please go through these ["xtragrid get filtered rows"](https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=xtragrid%20get%20filtered%20rows) search results to get the reference from DevExpress threads asked on their forum. – Niranjan Singh Sep 08 '16 at 09:14

2 Answers2

2

You can use two approaches to get filtered rows from GridView.

  1. The first one is to traverse through all visible rows from 0 to the GridView's RowCount, get row handles from visible indices via the GetVisibleRowHandle method, get the rows' underlying objects via the GetRow method, and insert these rows in a different IList.
  2. The second approach is to use the GridView's DataController.GetAllFilteredAndSortedRows() method. This method returns IList of currently visible rows in the current sort order.

References:
Getting Filtered Rows
How to get filtered rows
XtraGrid GridView : How to get the filtered rows - If datasource is datatable
how to get the xtragrid filtered and sorted datasource?

If you didn't find the way to implement this then go through documentation to get correct methods to fetch the data.

Hope this help..

Community
  • 1
  • 1
Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75
  • In your reference i found this :https://www.devexpress.com/Support/Center/Question/Details/Q303908 but what is exactly ColumnView ? – Ehsan Akbar Sep 08 '16 at 10:42
  • [ColumnView](https://documentation.devexpress.com/#WindowsForms/clsDevExpressXtraGridViewsBaseColumnViewtopic) is the base class of the GridView which generally create in Designer class if you drag-drop grid control.. there are different views for Grid Control so go through documentation to know more about these.. It is good that you found the answer.. :) – Niranjan Singh Sep 08 '16 at 11:21
1

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();
Ehsan Akbar
  • 6,977
  • 19
  • 96
  • 180