2

I am trying to implementing a barcode reader into my C# application. I understand that the barcode scanner works just like we type something on the keyboard. I have a textbox which the user will scan the barcode. And it works just fine, the number appears on the textbox. then I have a datagridview which has textboxes and a couple of comboboxes which are bound to the mysql database.

after the user scans the barcode into the textbox (this part is OK), then the system will automatically search inside the database for the matching barcode number (for this part is OK too). I am using this code for the searching part:

private void barcodeTextBox_KeyPress(object sender, KeyPressEventArgs e)
    {
        string synthetic_color_no = this.barcodeTextBox.Text;

        this.synthetic_colorTableAdapter.FillByBarcode(asi_softwareDataSet.synthetic_color, synthetic_color_no);
        this.synthetic_warehouseTableAdapter.Update(asi_softwareDataSet.synthetic_warehouse);
    }

with this code, now the item inside my datagridview combobox is sorted & only shows the matching barcode number inside the dropdown menu.

my problem is: I want it to be automatically display/select the matching barcode number inside the datagridview combobox dropdown which is bound to the mysql database so that the user doesn't have to click the combobox and select the number on their own. They would just scan & scan & scan.

Please note that unlike the regular ComboBox control, the DataGridView ComboBox types doesn't have a SelectedItem/SelectedValue/SelectedIndex property for retrieving the currently selected object. I have tried the solution on these site1 , site2 , site3 , but none work for me.

I've been working on this for almost a week and still no clue. your help is much appreciated. thanks

Community
  • 1
  • 1
  • [URGENT] won't get people to help you more quickly. – Otiel Dec 01 '11 at 07:59
  • my deadline is by the end of this week, that's why I posted with urgent sign. but, thanks anyway for viewing this – Aurelius Anugrah Sugianto Dec 01 '11 at 08:08
  • I don't know about your specific problem, but maybe you could use a `TextBox` with [autocompletion](http://stackoverflow.com/questions/2452663/autocomplete-a-textbox-in-c-sharp)? – Otiel Dec 01 '11 at 08:19
  • hmmm, and how do I do that? textbox1.autocomplete = true ? – Aurelius Anugrah Sugianto Dec 01 '11 at 08:29
  • See the [link](http://stackoverflow.com/questions/2452663/autocomplete-a-textbox-in-c-sharp) in my previous comment. – Otiel Dec 01 '11 at 08:40
  • after trying it, I think it doesn't do anything to my barcodetextbox. As I specified above, my problem is: I want it to be automatically display/select the matching barcode number inside the datagridview combobox dropdown which is binded to the mysql database. so that the user doesn't have to click the combobox and select the number on their own. they would just scan & scan & scan. – Aurelius Anugrah Sugianto Dec 01 '11 at 09:00
  • @AureliusAnugrahSugianto you need to provide more code detailing how you are providing the values to the datagridview combobox - setting the value of the cell should work so long as the value matches the ValueMember of the combobox columns backing source. It is hard to tell what you have done wrong without seeing more code. – David Hall Dec 01 '11 at 16:49
  • @DavidHall "setting the value of the cell should work so long as the value matches the ValueMember of the combobox columns backing source" well that's exactly what I did, but unfortunately it doesn't work. I will Update my question ASAP. thanks – Aurelius Anugrah Sugianto Feb 09 '12 at 06:09

1 Answers1

0
for (var i = 0; i < dataGridView1.Rows.Count - 1; i++) {                
    _module = dataGridView1.Rows[i].Cells[1].Value.ToString();            
}
FelixSFD
  • 6,052
  • 10
  • 43
  • 117