I'm doing a checador program where I have a table in DataGridView
and scan with a barcode reader to fill TextBox
, when it detects some code that matches what has been inserted increases in 1 the value in the Captured column and clears the TextBox
to be able to do it again, all this works correctly.
The problem comes when I want to apply a condition, so if you enter a code whose value in the Captured column is equal to the Requested column (understand) that all the necessary units have already been captured and are not needed anymore) no longer enter the part where the counter increases and only display a message on the screen with the text Unidades Completas
, but it does not matter how you organize the if
always enters the condition although in theory it does not comply, increases the counter and displays the message.
I leave the code of my function below:
if (e.KeyChar==Convert.ToChar(Keys.Enter))
{
foreach (DataGridViewRow fila in dataGridView1.Rows)
{
int b = Convert.ToInt32(fila.Cells[2].Value);
int c = Convert.ToInt32(fila.Cells[3].Value);
if (fila.Cells[2].Value == fila.Cells[3].Value)
{
MessageBox.Show("UNIDADES COMPLETAS");
}
else
{
String a = null;
a = Convert.ToString(fila.Cells[0].Value);
if (a == txtCodigo.Text)
{
int n = Convert.ToInt32(fila.Cells[3].Value);
n = n + 1;
fila.Cells[3].Value = n;
}
}
}
txtCodigo.Text = null;
}
The Int
that are declared occupy them in an attempt to change the way to do if
but the result is the same, then I show the initial table.
and what happens when I enter any code:
I understand that it is an error in my if
but sincerely I do not understand the behavior, I hope somebody can guide me, thank you very much in advance