From: Matthijs de Z on 9 Jun 2010 05:15 Hi, I need to get the indexof to select the correct item in a combobox that's filled using valuemember and displaymembers using bindingsource. (db.FaVLists is an entity mapping to a mysql database table) private void getCurrentFavListsInDB() { _favListManagerWorker.FillFavListsInDBComboboxes(_favListsInDBcomboBoxBindingSource,_openFavListsInDBcomboBoxBindingSource); _favListsInDBcomboBox.ValueMember = "FavListID"; _favListsInDBcomboBox.DisplayMember = "FavListName"; _favListsInDBcomboBox.Text = String.Empty; _favListsInDBcomboBox.SelectedIndex = -1; _favListsInDBcomboBox.Text = "Choose list"; _openFavListToolStripComboBox.ComboBox.DataSource = _openFavListsInDBcomboBoxBindingSource; _openFavListToolStripComboBox.ComboBox.ValueMember = "FavListID"; _openFavListToolStripComboBox.ComboBox.DisplayMember = "FavListName"; _openFavListToolStripComboBox.ComboBox.Text = String.Empty; _openFavListToolStripComboBox.SelectedIndex = -1; _openFavListToolStripComboBox.Text = "Choose list"; } public void FillFavListsInDBComboboxes(System.Windows.Forms.BindingSource myBindingSource1, System.Windows.Forms.BindingSource myBindingSource2) { var favListsInDB = from myResult in db.FaVLists select myResult; myBindingSource1.DataSource = favListsInDB; myBindingSource2.DataSource = favListsInDB; } during some actions (deletion or adding favlists) I reload the comboboxes, because the content changes. But if I already used a combobox to open a favlist that is still available, I want the combobox to be set to that item. I would like to get the indexof int within the combobox by using the FavListID (valuemember). How can I do this? kind regards, Matthijs
|
Pages: 1 Prev: ConfigurationManager not found Next: What kind of serialization method should be used |