ozisak
ozisak

Reputation: 13

barcode scanning

I am making a basic windows form app. One of the forms just has a textbox and button on it. Beside this, I have a database on sql server. In my database, there is one table (consists of ProductID, productName, NoOfStock and Price).

ProductID's are all barcodes that are belonging to real world products such as handcream, candy etc..

When I get my product details via barcodes from other controls such as combobox, there is not any problem. BUT, **The problem is or My question is ** , when I scan my barcode, I can get it directly on my textbox. After having the barcode, I want to see the name of the product (ProductName) on messagebox or on a label without clicking any button or enter etc..

In other words, i want my system to work like supermarkets.. a staff does not require to click on anything on the monitor, just scans the barcode and gets the details immediately.*

I think its related to an event, but which one?

Upvotes: 0

Views: 1818

Answers (3)

DrCopyPaste
DrCopyPaste

Reputation: 4117

My first guess was also to use the TextBox.TextChanged-Event, but reading your comments that does not work, now that I think about it, it makes sense. Most scanners "just" work like a keyboard from the perspective of the computer they are attached to (so they send keys one by one...). And also (as pointed out by icemanind) most barcode scanners are (or can be) configured to terminate their input by some pre-configured key (in most cases it is Enter or Tab, but you should be able to easily find that out looking into the manual or just looking at what keys come in when you scan)

So what you should do instead is subscribing to the KeyPress-Event (I guess keydown could also work, but I'd say it's unlikely the scanner will send a termination key and then hold it)

And then you check in that event whether the termination key was sent, if so you check the textbox's text contents and try to look up the data from your product database.

Upvotes: 1

Icemanind
Icemanind

Reputation: 48686

Depending on the make and model of your barcode scanner, usually there is an instruction manual that has a page of barcodes used to denote a terminator code, as shown here on this SuperUser question.

What you need to do is find this page and program your barcode scanner to automatically TAB or CR after its done inputting the barcode. Once you do this, THEN you can use the TextChanged event to detect when your terminator (TAB or CR) code has come through, then you can handle it!

If you choose TAB as your terminator, then you can simply handle the Leave event, because it'll automatically tab out of the textbox, thus leaving focus from the textbox.

Upvotes: 0

Dmitry Sadakov
Dmitry Sadakov

Reputation: 2158

You probably want the TextChanged event fired on the textbox when the barcode gets scanned.

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.textchanged(v=vs.110).aspx

Upvotes: 0

Related Questions