this is my code to show the data in textboxes因此,我试图制作一个Casher系统,但是在逐行显示数据时遇到麻烦,每当用户扫描我希望datagridview显示它的项目时
答案 0 :(得分:0)
尝试一下 表单加载:
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();
}
}