Improve Barcode search in a Textbox C#

前端 未结 5 1082
死守一世寂寞
死守一世寂寞 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:57

    I recall how I did this with success.

    I put Timer control in my application with a Interval of a second (1000 milli's). Then I set the Form.KeyPreview property to True.

    In the Form Key Press event I store the key strokes. In the Timer.Tick event check if the length of the recorded key strokes exceeds 12 or so characters.

    Then fire off the call to SQL, once. When you return a record successfully (or if the textbox contains greater than say 20 chars) clear the stored key strokes.


    See update, as at March 2019: https://stackoverflow.com/a/55411255/495455

提交回复
热议问题