Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I work on c# windows desktop application on POS Form for pharmacy

I need to read barcode to datagridview for every item

AND when read another item again go to next line

for every reading barcode

so are there are any sample for pos form with datagridview

on GitHub or any web site

What I have tried:

private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
    e.SuppressKeyPress = true;
    int iColumn = dataGridView1.CurrentCell.ColumnIndex;
    int iRow = dataGridView1.CurrentCell.RowIndex;
    if (iColumn == dataGridView1.Columncount-1)
    {
        if (dataGridView1.RowCount > (iRow + 1))
        {
            dataGridView1.CurrentCell = dataGridView1[1, iRow + 1];
        }
        else
        {
            //focus next control
        }
    }
    else
        dataGridView1.CurrentCell = dataGridView1[iColumn + 1, iRow];
}
Posted
Updated 11-Sep-21 10:14am

1 solution

The problem is that most scanners are configured to act like a keyboard - and there is no way to tell exactly where any particular keypress came from: it could be from a scanner and the next could be a "real" keyboard. Windows doesn't track keypresses like that.

What you need to do is talk to the manufacturers of the actual scanner you are using and find out how to add specific lead-in and tail-out sequences to the codes it provides. You can then detect the start and end of the scanned code, and that lets you "divert" it to anything you want.

When you have the scanner doing that, it's just a matter of previewing all keyboard input at Form level: Handle keyboard input at the Form level - Windows Forms .NET | Microsoft Docs[^] Then you can do what you want with the scanned codes!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900