How to count specific values in a column of datagridview column

前端 未结 2 1413
忘掉有多难
忘掉有多难 2021-01-25 17:19

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

2条回答
  •  梦毁少年i
    2021-01-25 18:04

    You can count what you need this way:

    var count= this.dataGridView1.Rows.Cast()
                   .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 using Cast(), then you can perform any query on it, using linq.

提交回复
热议问题