lundi 9 mars 2015

Use LINQ to remove the first column in a DatagGridView for each control in a ControlCollection

So, the non-LINQ way would be something like this:



foreach(Control cont in panel1.Controls)
{
if (cont is DataGridView)
{
var grid = cont as DataGridView;
grid.Columns.RemoveAt(0);
}
}


I have tried doing this in Linq. Its more for the learning experience than specifically doing it the best way. Anyway this is where I am at so far, but it does not work obviously.



panel1.Controls = panel1.Controls
.AsParallel()
.OfType<DataGridView>()
.Select(grid => grid.Columns
.OfType<DataGridViewColumn>()
.Skip(1));


So what can be done to amend the linq query?


Aucun commentaire:

Enregistrer un commentaire