|
I have a combo box bound to an ObservableCollection<classmodel>. The entity passed into the view has an instance of a ClassModel. I want to select the item in the combo which matches the entite's ClassModel.
So far im lookping over the ObservableCollection to find the item:
foreach (var jobClass in Classes)
{
if (jobClass.Id == JobRevision.JobClass.Id)
{
SelectedClass = jobClass;
break;
}
}
is there a way to do this without loopping?
Thanks
If it's not broken, fix it until it is
modified 12-Jan-13 21:27pm.
|
|
|
|
|
Can't you bind the SelectedValuePath of the combo to the SelectedJobClass.ID
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Not sure I understand. Can you post an example?
If it's not broken, fix it until it is
|
|
|
|
|
It is just the standard combo binding or am I missing something?
<ComboBox x:Name="cboType" Grid.Row="2" Grid.Column="1" ItemsSource="{Binding AttrTypeList,Mode=TwoWay}"
DisplayMemberPath="AttrType"
SelectedValuePath="AttrTypeID"
SelectedValue="{Binding SelectedAttrCostume.AttrTypeID,Mode=TwoWay}"/>
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Yes, but what are 'AttrType' and 'AttrTypeID' and 'SelectedAttrCostume'? Are they properties on the entities in the AttrTypeList list?
If it's not broken, fix it until it is
|
|
|
|
|
Ok, I don't know what's wrong, but I still cannot get this to work...
My combo is bound to an ObservableCollection<lookupmodel>, as in:
private ObservableCollection<LookupModel> _Departments;
public ObservableCollection<LookupModel> Departments
{
get { return _Departments; }
set
{
if (_Departments != value)
{
_Departments = value;
RaisePropertyChanged("Departments");
}
}
}
private LookupModel _SelectedDepartment;
public LookupModel SelectedDepartment
{
get { return _SelectedDepartment; }
set
{
if (_SelectedDepartment != value)
{
_SelectedDepartment = value;
RaisePropertyChanged("SelectedDepartment");
}
}
}
Here is the lookup model:
public class LookupModel : _BaseModel
{
private int _Id = 0;
public int Id
{
get { return _Id; }
set
{
if (_Id != value)
{
_Id = value;
RaisePropertyChanged("Id");
}
}
}
private string _Caption = string.Empty;
public string Caption
{
get { return _Caption; }
set
{
if (_Caption != value)
{
_Caption = value;
RaisePropertyChanged("Caption");
}
}
}
}
And in the vie model I have:
SelectedDepartment = Job.Department;
Job.Department is an instance of a lookup model with the selected department in it.
When I run this, the department is not selected in the combo.
What am I doing wrong here???
Thanks
If it's not broken, fix it until it is
|
|
|
|