Ehsan Akbar
Ehsan Akbar

Reputation: 7299

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?

Upvotes: 1

Views: 11192

Answers (2)

Ehsan Akbar
Ehsan Akbar

Reputation: 7299

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();

Upvotes: 1

Niranjan Singh
Niranjan Singh

Reputation: 18270

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..

Upvotes: 3

Related Questions