如何检查列中是否已存在记录?

时间:2014-01-29 10:02:41

标签: c# datagridview

我有DataGridViewindex[0]

我如何知道此栏中是否已存在我输入的值并增加现有row["Quantity"]

 private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
      if (e.ColumnIndex == 0)
      {
          //some code
      }
 }

1 个答案:

答案 0 :(得分:0)

//check if the value in  same column is repeated dataGridView1:

for (int j = 0; j < dataGridView1.Columns.Count; j++)
{
    for (int i = 0; i < dataGridView1.Rows.Count; i++)
    {
        for (int k = 0; k < dataGridView1.Columns.Count; k++)
        {
            if (dataGridView1.Rows[i].Cells[j].Value.ToString() == dataGridView1.Rows[i].Cells[k].Value.ToString())
            {
                //you can increase  row["Quantity"] here 
                break;
            }
        }

    }
}