I am populating a combobox in WPF like this
_cviewPreferencesPresenter.ListOfOVUnits();
cmbOVUnits.SelectedItem = _cstrSelectdOVUnit;
_cstrDisplayedOVUnitID = cmbOVUnits.SelectedValue.ToString();
After the combobox loading i want to see the default value selected but i am not getting any value cmbOVUnits.SelectedItem is null.But the combobox is getting populated.
When i select some value in the combobox and click on apply button the value is not pertaining it is going to first value.
public void PopulateOVList(List<KeyValuePair<string, string>> lstOVData)
{
try
{
cmbOVUnits.DataContext = lstOVData;
cmbOVUnits.DisplayMemberPath = "Value";
cmbOVUnits.SelectedValuePath = "Key";
}
catch (FlukeException)
{
throw;
}
catch (Exception excException)
{
if (FlukeConstants.IsLoggerEnabled)
{
Common.LogApplicationExceptionMsg(excException);
}
throw new FlukeException(SeverityLevel.Fatal, LogLevel.Debug, excException,
FlukeExceptionConstants.FLK_ERR_COMMON_APPLICATIONEXCEPTION);
}
}
here i can see cmbOVUnits cmbOVUnits = {System.Windows.Controls.ComboBox Items.Count:0} is '0', even i though i am getting values in lstOVData.The DataContext have the values like cmbOVUnits.DataContext = Count = 14.
So obviously cstrDisplayedOVUnitID value will be null.How can i solve this?