简体   繁体   中英

How to check if a record already exist in column?

I have a DataGridView with a column index[0]

How can I know if value I entered already exists in this column and increase the existent row["Quantity"]

 private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
      if (e.ColumnIndex == 0)
      {
          //some code
      }
 }
//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;
            }
        }

    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM