Improve Barcode search in a Textbox C#

前端 未结 5 1072
死守一世寂寞
死守一世寂寞 2021-01-23 21:27

In a WinForm C# application I have a Barcode_textbox. In TextChanged event I have an SQL query to check for the TextBox.Text value in the database which is the barc

5条回答
  •  梦谈多话
    2021-01-23 21:45

    You could use the Validating event to check the content of the TextBox.
    Your user will be required to press the TAB key to change the current focus from the TextBox to the next control following the taborder and the validating event will be triggered

    private void textBox_BarCode_Validating(object sender, CancelEventArgs e)
    {
         // Code to check the barcode on the SQL database....       
         if(!ValidBarCode(textBox1.Text))
         {
               // Cancel the event and select the text to be corrected by the user.
               e.Cancel = true;
               textBox1.Select(0, textBox1.Text.Length);
         }
    

    }

    Suppose that the next control is the command that executes something using the Barcode inserted (Add)(or a textBox to insert the quantity of the item described by the barcode). After a while all the operation becomes a very natural data entry processing

提交回复
热议问题