基于上一列的值,特定列中的datagridview计数

时间:2018-10-03 17:13:11

标签: c# datagridview

我试图计算表的时间是,每次'status_id'= 1计数'dept_id'= 4

private void button2_Click(object sender, EventArgs e)
    {
        var count = this.dataGridView1.Rows.Cast<DataGridViewRow>()
           .Count(row => row.Cells["status_id"].Value.ToString() == "1");

        if (dataGridView1.Rows[count - 1].Cells["status_id"].Value.ToString() == "1")
        {
            var general = this.dataGridView1.Rows.Cast<DataGridViewRow>()
           .Count(row => row.Cells["dept_id"].Value.ToString() == "1");
            this.textBox2.Text = general.ToString();
        }

但是if条件不起作用,并且无论status_id为何,其在dept_id中都将全1计数

How the table looks

我仍然是C#的初学者

0 个答案:

没有答案