简体   繁体   中英

How to get the value of the selected item of a datagridview combobox

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

for (var i = 0; i < dataGridView1.Rows.Count - 1; i++) {                
    _module = dataGridView1.Rows[i].Cells[1].Value.ToString();            
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM