How to clear data readed by scanner from textbox to recieve another one?

Posted by Ahmedsa under C# on 2/20/2017 | Points: 10 | Views : 234 | Status : [Member] | Replies : 1
Problem

When read qr using barcode scanner for more than one it append the same textbox4 .

i need to clear data after every scanning done .

Details

I using usb scanner reader qr code with type metro logic working as keyboard

and using USB

i read data in textbox4 key down success

but problem if i read data for new qr code

it append in same text box

so that what i do to clear the data recieved before and prevent append to old

my code

private void textBox4_KeyDown(object sender, KeyEventArgs e)
{

string[] lines = textBox4.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

if (lines.Length > 4)
{
textBox1.Text = lines[1].Substring(lines[1].IndexOf(":") + 1);
textBox2.Text = lines[2].Substring(lines[2].IndexOf(":") + 1);
textBox3.Text = lines[3].Substring(lines[3].IndexOf(":") + 1);
textBox5.Text = lines[4].Substring(lines[4].IndexOf(":") + 1);
}

textbox4 read data from reader device then split them to textboxes




Responses

Posted by: A2H on: 2/20/2017 [Member] [MVP] Silver | Points: 25

Up
0
Down
You could clear the value in textbox by assigning an empty string to it
Sample Code

 private void textBox4_KeyDown(object sender, KeyEventArgs e)
{

string[] lines = textBox4.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

if (lines.Length > 4)
{
textBox1.Text = lines[1].Substring(lines[1].IndexOf(":") + 1);
textBox2.Text = lines[2].Substring(lines[2].IndexOf(":") + 1);
textBox3.Text = lines[3].Substring(lines[3].IndexOf(":") + 1);
textBox5.Text = lines[4].Substring(lines[4].IndexOf(":") + 1);
}
//Clear the textbox after reading the values
textBox4.Text = string.Empty;
}


Thanks,
A2H
My Blog

Ahmedsa, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response