I want to loop through DataGridViewRowCollection or DataGridViewSelectedRowCollection (users choice). I don't know how I can do it the simple way. Here is my Code:
List<DataGridViewRow> rows = new List<DataGridViewRow>();
if (dr == DialogResult.No)
foreach (DataGridViewRow row in dgvResult.Rows)
rows.Add(row);
else if (dr == DialogResult.Yes)
foreach (DataGridViewRow row in dgvResult.SelectedRows)
rows.Add(row);
int counter = 1;
foreach (DataGridViewRow row in rows)
{
//...
}
You may need Enumerable.Cast method.
List<DataGridViewRow> lst = dataGridView1.Rows.Cast<DataGridViewRow>().ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With