I have a WPF Application with two ComboBox
es.
When I select the first one the items related to the first combobox will be populated on the second one
Here is my select Property
public string SelectedApplication
{
set
{
if (_selectedApplication == value) return;
this._selectedApplication = value;
InitializeTransactionTypes();
}
get
{
return this._selectedApplication;
}
}
here i am checking a matching id between the two comboboxes to populate the second control items.
ObservableCollection<TransactionTypeViewModel> _transTypeObsList = new ObservableCollection<TransactionTypeViewModel>();
private void InitializeTransactionTypes()
{
if (_selectedApplication != null)
{
if (transactionTypes != null)
{
transactionTypes.Clear();
}
var getAppCode =
ApplicationVModel.GetAllApplications().FirstOrDefault(apps => apps.Name == _selectedApplication);
var transTypeList = TransactionTypeVModel.GetAllTransactionTypes()
.Where(t => getAppCode != null && t.Id == getAppCode.Id)
.ToList();
_transTypeObsList = new ObservableCollection<TransactionTypeViewModel>(transTypeList);
}
this.transactionTypes = _transTypeObsList;
NotifyPropertyChanged("TransactionTypes");
}
Lets say I select first combobox has {A,B,C,D} ...and the second combobox has {A'1,A'2,A'3}, when I select item from first Combobox the second combobo keeps populating items. I wanted to show only {A'1 for A} {B'1 for B} ...etc but now what it does is {A'1 A'1 A'1 ..... for A} {B'1 B'1 B'1 ....for B} for every select.
EDIT:
List of VM mapped from List of Model
public List<TransactionTypeViewModel> GetAllViewModelTransTypes()
{
TransactionTypeViewModels = TransactionTypeModel.GetAllTransactionTypes().Select(transType => new TransactionTypeViewModel
{
Id = transType.Id,
Name = transType.Name,
RequestMessageType = transType.RequestMessageType,
ResponseMessageTypes = transType.ResponseMessageTypes,
WsMethodName = transType.WSMethodName,
WsRequestXmlType = transType.WSRequestXmlType,
WsResponseXmlType = transType.WSResponseXmlType,
XsdFile = transType.XsdFile,
})
.ToList();
return TransactionTypeViewModels;
}
List of Observable VM from List of VM
public ObservableCollection<TransactionTypeViewModel> GetAllTransactionTypes()
{
TransactionTypeViewModelList = this.GetAllViewModelTransTypes();
ObservableTransactionType = new ObservableCollection<TransactionTypeViewModel>(TransactionTypeViewModelList);
return ObservableTransactionType;
}
EDIT:
private void InitializeTransactionTypes()
{
if (_selectedApplication != null)
{
var getAppCode =
ApplicationVModel.GetAllApplications()
.FirstOrDefault(apps => apps.Name == _selectedApplication);
var transTypeList = TransactionTypeVModel.GetAllTransactionTypes()
.Where(t => getAppCode != null && t.Id == getAppCode.Id);
transactionTypes = new ObservableCollection<TransactionTypeViewModel>(transTypeList);
NotifyPropertyChanged("TransactionTypes");
}
}