private void button1_Click(object sender, EventArgs e)
{
bool entryFound = false;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
object val1 = row.Cells[0].Value;
object val2 = row.Cells[1].Value;
object val3 = row.Cells[2].Value;
object val4 = row.Cells[3].Value;
if (val1 != null && val1.ToString() == textBox1.Text &&
val2 != null && val2.ToString() == textBox2.Text &&
val3 != null && val3.ToString() == textBox3.Text &&
val4 != null && val4.ToString() == textBox4.Text)
{
MessageBox.Show("Entry already exist");
entryFound = true;
break;
}
}
if (!entryFound)
{
dataGridView1.Rows.Add(textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text);
}
}