0
votes

when editing a specific record in a listview row, how do I get that value to the corresponding combobox selected item/value?

The combobox is in dropdownlist style mode, so the selected text wont work.

i tried this:

cbBrand.SelectedItem = lvMain.SelectedItems[0].SubItems[1].ToString();

but i get null in the corresponding combobox selecteditem... :(

2
what if you don't '.ToString()' the sub-item ?Seb
@Seb cbBrand.SelectedValue = lvMain.SelectedItems[0].SubItems[1]; gets me Unable to cast object of type 'ListViewSubItem' to type 'System.IConvertible'n3bi0s
I was asking for .SelectedItem instead of .SelectedValueSeb
@Seb nothing happens.. because it's passing a value... the ComboBox is configured like this: cb.DataSource = dt; cb.DisplayMember = "name"; cb.ValueMember = "id"; so it is expecting a value, and the item i think it's the name..n3bi0s

2 Answers

1
votes

I got it working like this:

int xcb;
xcb = this.cbBrand.FindString(lvMain.SelectedItems[0].SubItems[1].Text);
this.cbBrand.SelectedIndex = xcb;
0
votes

You can use the SelectedValue property.