編輯:下面的代碼工程! (我評論,建立,後來未註釋,它的工作)。Linq可觀察到的收藏投射錯誤
我有一個ObservableCollection
爲ListBox
。我只想根據顯示名稱選擇其中一些項目,因爲我不知道項目值。然而,我得到一個轉換錯誤(IEnumerable到ObservableCollection)。
ObservableCollection<ListBoxItem> unselectedcollection
= new ObservableCollection<ListBoxItem>
(dt.AsEnumerable()
.Select(i => new ListBoxItem(i[ColumnNames.LISTNAMECOL].ToString(),
i[ColumnNames.LISTVALUECOL].ToString())));
ObservableCollection<ListBoxItem> selectedcollection
= new ObservableCollection<ListBoxItem>
(from item in unselectedcollection.AsEnumerable()
where (item.Name == "firstName"
|| item.Name == "secondName"
|| item.Name == "thirdName")
select item);
我已經試過我能想到的各種鑄造選項。我錯過了什麼?
也包括你的第一個集合('unselectedcollection'),這可能是問題的根源。 –
什麼是未選擇收藏的類型? – PoweredByOrange
我已將它添加到原始問題 – SeeMoreGain