0

以下代码给了我这个错误:https ://prnt.sc/q4truq

    private void Form1_Load(object sender, EventArgs e)
    {
        MyDataGridView.Columns.Insert(0, new DataGridViewCheckBoxColumn());
        MyDataGridView.Rows.Add(4);
        MyDataGridView.Rows[0].Cells[0].Value = true;
        MyDataGridView.Rows[1].Cells[0].Value = false;
        MyDataGridView.Rows[2].Cells[0].Value = true;
        MyDataGridView.Rows[3].Cells[0].Value = false;
        MyDataGridView.Rows[4].Cells[0].Value = true;

        string strResults = (MyDataGridView.Rows.Cast<DataGridViewRow>()
                           .Where(c => Convert.ToBoolean(r.Cells[0].Value).Equals(true))
                           .Count(s => Convert.ToInt32(t.Cells[0].Value))).ToString();
    }
4

1 回答 1

0

这个错误是因为已经没有名为 r 的变量但是有 c 所以这是你的解决方案我的朋友 ^_^

        private void Form1_Load(object sender, EventArgs e)
        {
            MyDataGridView.Columns.Insert(0, new DataGridViewCheckBoxColumn());
            MyDataGridView.Rows.Add(4);
            MyDataGridView.Rows[0].Cells[0].Value = true;
            MyDataGridView.Rows[1].Cells[0].Value = false;
            MyDataGridView.Rows[2].Cells[0].Value = true;
            MyDataGridView.Rows[4].Cells[0].Value = true;

            int strResults = MyDataGridView.Rows.Cast<DataGridViewRow>()
                           .Where(c => Convert.ToBoolean(c.Cells[0].Value).Equals(true)).ToList().Count;
            MessageBox.Show("" + strResults);
        }
于 2019-12-02T03:40:58.073 回答