I want to set DataGridView’s columns to ReadOnly except one or two columns.
I was trying to do this.
dgv.Columns.AsQueryable().ForEach(col=>col.ReadOnly=true);
But I found that these extension methods are not available at DataGridViewColumnCollection
How can I do the same by this way
The original idea of LINQ is not to modify existing collections, but to return new ones, so methods like
ForEachare not among the default LINQ methods.You could easily write your own ForEach like:
and so your code would become:
BTW…
it is really worthwhile writing it as LINQ extension, when with 2 lines of old imperative-school code you can do the same ?