In a DataGridView I need to count how many duplicate values a column has.
This is my Datagridview:
For example, I'd like to count how many "X" I have in my "RisFin" column, and put the result in a textbox.
You can count what you need this way:
var count= this.dataGridView1.Rows.Cast<DataGridViewRow>()
.Count(row => row.Cells["RisFin"].Value == "X");
this.textBox1.Text = count.ToString();
Using linq queries you can simply do many things with your grid. and the key point is casting the Rows collection to an IEnumerable<DataGridViewRow> using Cast<DataGridViewRow>(), then you can perform any query on it, using linq.
using System.Linq;
Rowscollection to anIEnumerable<DataGridViewRow>usingCast<DataGridViewRow>(), then you can perform any query in it, using linq.