Problem showing selected value of combobox when it is bind to a List<T> using Linq to Entities
Posted
by Syed Mustehsan Ikram
on Stack Overflow
See other posts from Stack Overflow
or by Syed Mustehsan Ikram
Published on 2010-01-29T05:53:16Z
Indexed on
2010/04/17
15:03 UTC
Read the original article
Hit count: 250
I have a combobox which is has itemtemplate applied on it and is bind to a List of entity return using linq. i m using mvvm. It is bind to it successfully but when i set the selected value of it from code at runtime to show the selected value coming from db it doesn't select it. For reference here is my combobox xaml.
SelectedValue="{Binding Path=SelectedManufacturer}"
Grid.Column="3" Grid.Row="2" Margin="20,9.25,68,7.75"
ItemTemplate="{StaticResource ManufacturerDataTemplate}" TabIndex="6"/>
Here is my part from code behind from viewModel.
List currentManufacturers = new List();
tblManufacturer selectedManufacturer = null;
public List CurrentManufacturers { get { return currentManufacturers; } set { currentManufacturers = value; NotifyPropertyChanged("CurrentManufacturers"); } }
public tblManufacturer SelectedManufacturer
{
get
{
return selectedManufacturer;
}
set
{
selectedManufacturer = currentManufacturers.Where(mm => mm.ManufacturerID == Convert.ToInt32(selectedDevice.tblManufacturer.EntityKey.EntityKeyValues[0].Value)).First();
NotifyPropertyChanged("SelectedManufacturer");
}
}
© Stack Overflow or respective owner