Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Answer
Validating Datagridview in a form.
qing ryder
7y
216
1
Reply
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;
// Displays the MessageBox.
result = MessageBox.Show(message, caption, buttons);
if
(result == System.Windows.Forms.DialogResult.OK)
{
return
;
}
}
else
{
resultVV f3 =
new
resultVV();
f3.ShowDialog();
this
.Hide();
}
}
}
}
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Primary Key Violation
Failing to make a patch via API using c# and json