i have a form, with datagrid where inputs are collected, together with a submission button. at the submission of this data, i want to validate the datagrid to check for empty cells.
from my code, the datagrid wont be validated until i have exited then it keeps bugging me with the messagebox message.
here is my code:
- private void button3_Click(object sender, EventArgs e)
- {
- foreach (DataGridViewRow rw in this.dataGridView1.Rows)
- {
- for (int i = 0; i < rw.Cells.Count; i++)
- {
- if (rw.Cells[i].Value == null || rw.Cells[i].Value == DBNull.Value || String.IsNullOrWhiteSpace(rw.Cells[i].Value.ToString()))
- {
- string message = "Sorry, But some Fields are Empty, Therefore, you cannot Proceed";
- string caption = "Error Detected in Input";
- MessageBoxButtons buttons = MessageBoxButtons.OK;
- DialogResult result;
-
-
-
- result = MessageBox.Show(message, caption, buttons);
-
- if (result == System.Windows.Forms.DialogResult.OK)
- {
- return;
- }
- }
- else
- {
- resultVV f3 = new resultVV();
- f3.ShowDialog();
- this.Hide();
- }
- }
- }
- }