简体   繁体   中英

how can i add data from barcode scanner to Datagridview Row by Row

这是我的代码,用于在文本框中显示数据,因此我试图制作一个Casher系统,但是在逐行显示数据时遇到了麻烦,每次用户扫描项目时我都希望datagridview显示它

try this form load:

        private void Form1_Load(object sender, EventArgs e)
         {
            /*form load*/

            dataGridView1.Columns.Add("Column1", "qty");
            dataGridView1.Columns.Add("Column2", "price");


         }



        int RowIndex = 0;
        private void txtBarcode_KeyDown(object sender, KeyEventArgs e)
        {

            if (e.KeyCode==Keys.Enter)
            {  /* .....
                .....
                ..... Sql connection*/

                while (reader.Read()) {

                    dataGridView1.Rows.Add();
                    dataGridView1.Rows[RowIndex].Cells[0].Value = reader.GetString(2);
                    dataGridView1.Rows[RowIndex].Cells[1].Value = reader.GetString(3);


                    RowIndex++;

                }
                reader.Close();

            }
        }

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM