Reputation: 21
Can some one please tell me Why is this not possible? I am new to WPF and Linq I am trying to select a value from my first combobox and display the related values in my second combobox.
private void initializeTransactionTypes()
{
var getAppCode = applicationVModel.GetAllApplications().FirstOrDefault(apps => apps.AppCode == selectedApplication);
var transTypeList = (from transName in transTypeVModel.GetAllTransactionTypes()
where transName.Id == getAppCode.Id
select transName.Name).ToList();
//cast list of string to observ.
ObservableCollection<TransactionTypeViewModel> transTypeObsList =
new ObservableCollection<TransactionTypeViewModel>(transTypeList);
TransactionTypes = transTypeObsList;
NotifyPropertyChanged("TransactionTypes");
// }
//}
}
// Bind trans type combobox to this
public ObservableCollection<TransactionTypeViewModel> TransactionTypes
{
set
{
initializeTransactionTypes();
NotifyPropertyChanged("TransactionTypes");
}
get
{
return _transactionType;
}
}
Upvotes: 0
Views: 1125
Reputation: 144196
It looks like transTypeList
is a List<string>
(assuming transName.Name
is a string) and you are trying to use it to initialise an ObservableCollection<TransactionTypeViewModel>
.
The constructor for ObservableCollection<T>
requires a List<T>
so you need to provide a List<TransactionTypeViewModel>
instead.
It looks like you just need to change your linq query to:
var transTypeList = (from transName in transTypeVModel.GetAllTransactionTypes()
where transName.Id == getAppCode.Id
select transName).ToList();
or alternatively:
var transTypeList = transTypeVModel.GetAllTransactionTypes()
.Where(t => t.Id == getAppCode.Id)
.ToList();
Upvotes: 0