I struggle with selecting proper item in winforms combobox. Previously I described in detail here but I think that problem remain unsolved cause I use one form for add/edit record. so on form load I have
private void AddEditForm_Load(object sender, EventArgs e)
{
PopulateComboBoxLanguage();
}
private void PopulateComboBoxLanguage()
{
comboBoxLang.DataSource = Enum.GetValues(typeof(Book.EnumLang));
}
and on edit action I want to populate form with existing data and everything is populated as it should except combobox where first item from EnumLang is always displayed.
from my second constructor I call PopulateWithExisingData(book)
where I use
comboBoxLang.SelectedItem = book.Language;
but even when passed book.Language
is set to German SelectedItem
is always null on debug mode.
p.s. I tried with comboBoxLang.SelectedItem = (book.EnumLang)book.Language;
also with SelectedValue but remains the same.
Once more I guess that problem is on populating combobox on page load but I don't know is it and how to fix that.
Please ask for more info.