How to count specific values in a column of datagridview column

前端 未结 2 1411
忘掉有多难
忘掉有多难 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条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-25 17:59

    Well, you could just iterate through the rows and increment your counting variable if row.Cells[0] is "X". Here's a LINQ solution.

    int xCount = dataGridView.Rows
                    .Cast()
                    .Select(row => row.Cells["RisFin"].Value.ToString())
                    .Count(s => s == "X");
    

提交回复
热议问题