如何在同一列中检查存在的值?

时间:2014-02-01 13:20:34

标签: c# winforms datagridview

我有数据网格视图Datagrideview1 我如何检查Cell End Edit事件 每次重复相同的数字3232时,将数量(1)增加“1”

 private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                for (int i = 0; i < dataGridView1.RowCount; i++)
                {
                    string itemInfo;
                    itemInfo = dataGridView1.Rows[i].Cells[0].Value.ToString();
                    var matchedRow = dataGridView1.Rows.OfType<DataGridViewRow>()
                                     .FirstOrDefault(row => row.Cells[0].Value != null &&
                                                          row.Cells[0].Value.Equals(itemInfo[0]));
                    if (matchedRow != null)
                    {
                        int qty = (int)matchedRow.Cells[3].Value + 1;
                        double price = (double)matchedRow.Cells[4].Value;
                        matchedRow.Cells[7].Value = price * qty;
                    }
                }
            }

enter image description here

0 个答案:

没有答案