10 TIPs - To Become a Good Developer/Programmer
Why Join
Become a member
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
C# Corner Home
Technologies
Monthly Leaders
ASK A QUESTION
Forum guidelines
Qing Ryder
1.9k
202
14.1k
Validating Datagridview in a form.
Oct 12 2017 10:57 AM
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();
}
}
}
}
Reply
Answers (
1
)
Primary Key Violation
Failing to make a patch via API using c# and json