I want to check the cells of my datagridview. also if atleast one of the cell is empty, it will return "false"
and so, I have this method WHICH is i knew is not correct. since if ever the last item in the array has value, it will make "checking" a true. I just cant get the correct code or logic for what i plan to make.
public void checker()
{
string[] check = new string[50];
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
check[i] = dataGridView1.Rows[i].Cells[0].Value.ToString();
}
for (int e = 0; e < check.Length; e++)
{
if (check[e] == null)
{
checking = "false";
}
else
{
checking = "true";
}
}
}
You could just return from the function the very first time you find an empty cell. You could try using the following approach:
public void checker()
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
var value = dataGridView1.Rows[i].Cells[0].Value.ToString();
if (string.IsNullOrWhiteSpace(value))
{
checking = false;
return;
}
}
// If we have reached this far, then none of the cells were empty.
checking = true;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.