private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { int i = dataGridView1.Rows.Count; for (int j = 0; j < i; j++) { if (dataGridView1.Rows[j].Cells[0].Value == null) { MessageBox.Show("Field 1 is empty"); } else if(dataGridView1.Rows[j].Cells[2].Value == null) { MessageBox.Show("Field 2 is empty"); } else if (dataGridView1.Rows[j].Cells[2].Value == null) { MessageBox.Show("Field 3 is empty"); } } }
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { // Validate the CompanyName entry by disallowing empty strings. if (dataGridView1.Columns[e.ColumnIndex].Name == "CompanyName") { if (String.IsNullOrEmpty(e.FormattedValue.ToString())) { dataGridView1.Rows[e.RowIndex].ErrorText = "Company Name must not be empty"; e.Cancel = true; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)