简体   繁体   中英

Set vb.net combobox SelectedIndex by value

I am working on a tool that saves data into a database to later retrieve it and display in the same form

I save data into the database using integer id's

In order to set combobox values I have tried the following

frm.statusComboBox.SelectedValue = initiativeDataGridView.SelectedRows(0).Cells(initiativeDataGridView.Columns("initiativeStatus_Id").Index()).Value

I understand that I am in the wrong, since I need to set the combobox selectedIndex and not the selectedValue. So I guess my main question is how do I identify the combobox index for a particular value member?

Try using ComboBox.SelectedItem instead, but you should add the item as well, so it appears in the dropdownlist. Working with Indexes of ComboBox isn't the best idea, because they can change as you sort your ComboBox, delete or add items.

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