Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert generic list to BindingList<T>

I have BindingList object which is attched with DataGridView.

BindingList<FilesToProcessDataModels> Listfiles = new BindingList<FilesToProcessDataModels>();
dataGridFiles.DataSource = Listfiles;

I want to filter items list by given condition in Where. like following:

dataGridSheets.DataSource = Listfiles.Where(i => i.Status == FileStatus.NotProcessed).ToList();

Above code is working fine but I want to assign filter resut to the same type object [Listfiles] instead datagrid,

When I am doing this:

Listfiles = Listfiles.Where(i => i.Status == FileStatus.NotProcessed).ToList();

it gives following erorr

[Cannot implicitly convert type 'System.Collections.Generic.List to BindingList']

How can I convert generic list to BindingList<FilesToProcessDataModels>?

like image 819
Zeeshanef Avatar asked Dec 05 '13 11:12

Zeeshanef


1 Answers

below is the standard way - tho google should show this up easily -even on SO:

Convert IList<T> to BindingList<T>

var listFiles= new List<FilesToProcessDataModels>();
var listBindingFiles = new BindingList<FilesToProcessDataModels>(listFiles);
like image 140
jim tollan Avatar answered Sep 18 '22 17:09

jim tollan