Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one textbox and i will read to the values with barcode scanner continuous with textchanged event to listbox.
What is the best procedure for this?

What I have tried:

private void tb_vonalkod_TextChanged(object sender, EventArgs e)

Textbox1.Text=ListBox1.Text;
Posted
Updated 4-Feb-20 0:33am
Comments
Richard MacCutchan 4-Feb-20 6:26am    
Why are you copying a ListBox item into the TextBox? You need to do it the other way round.
Member 13873270 4-Feb-20 6:34am    
I will reverse this method. Textbox to Listbox

1 solution

You may use the Validated event of the textbox instead. And Richard is right, you should populate the listbox with the text from the textbox, not the other way around. Moreover, there is no point in using the Text property on a listbox, since by essence it is meant to display a list of items. Better add to its Items collection instead.
C#
private void tb_vonalkod_Validated(object sender, EventArgs e)
{
   // Uncomment the next line to empty the listbox if needed
   // ListBox1.Items.Clear();
   ListBox1.Items.Add(TextBox1.Text);
}
 
Share this answer
 
Comments
Member 13873270 4-Feb-20 6:59am    
It works fine, but I would like to earn the validation should be automatic, so if I read a value in the textbox, it should be automatically included in the listbox, and back to the focus to empty textbox.

private void TextBox1_Validated(object sender, EventArgs e)
{
ListBox1.Items.Add(TextBox1.Text);
TextBox1.Clear();
TextBox1.Focus();
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900