We can't tell you, because we don't know exactly what you are doing, where the barcode info is going, ... and we can't run your code to find out (we don't have your scanner, your
pro
class, or any idea what it's
GetProdcutBar
method is doing.
So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger - a quick Google for "Visual Studio debugger" should give you the info you need to get started with it.
Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.
Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
But before you do that, stop swallowing exceptions!
When you write code like this:
try
{
int sum = 0;
for (int i = 0; i < dataGridView1.Rows.Count; ++i)
...
}
catch
{
}
The chances are that you are throwing away information you really do need in order to fix problems. Either don't use a
try...catch
block at all, or use the Exception object to help you fix problems: log it, show it to the user, output it to the debug console, whatever - but just catching everything and ignoring it means you don't even know that a problem has happened until it shows up as a problem elsewhere, or elsewhen...