I'm trying to select multiple rows from a DataGridView instead of iterating with a for-each loop.
I can select 1 item using this code:
DataGridViewRow row2 =
(from DataGridViewRow r in dgView.Rows
where r.Cells["name"].Value.ToString().Equals("Akins Ford")select r).FirstOrDefault();
But when I try to select multiple rows, using this code:
List<DataGridViewRow> rows2 =
(from DataGridViewRow r in dgView.Rows
where r.Cells["status"].Value.ToString().Equals("active")select r);
I got an error:
Error 2 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'System.Collections.Generic.List'. An explicit conversion exists (are you missing a cast?) C:\Software\Json\Json\Form1.cs 188 18 Json
dataGridView1.Rows.Cast<DataGridViewRow>().Where(x => x.Cells["status"].Value.ToString() == "active").ToList().ForEach(x => x.Selected = true);