As the topic says: Is there a way to return a list of distinct values from a certain Column of a DataGridView?
This should do what you asked for:
var vv = dataGridView1.Rows.Cast<DataGridViewRow>()
.Select(x => x.Cells[yourColumn].Value.ToString())
.Distinct()
.ToList();
Note that the simple version above assumes that there are only valid values. If you also may have new rows or empty cells you may want to expanded it like this:
var vv = dataGridView1.Rows.Cast<DataGridViewRow>()
.Where(x => !x.IsNewRow) // either..
.Where(x => x.Cells[column].Value != null) //..or or both
.Select(x => x.Cells[column].Value.ToString())
.Distinct()
.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