我正在尝试在字符串中搜索observablecollection的项目。
我在下面的代码中尝试。
for (int j = 0; j < DBControl.Instance.SelectLanguagesFromDatabase().Count; j++)
{
if ( dominatorIntern.ProgrammingLanguages.Contains(ProgrammingLanguagesList[j] )
ProgrammingLanguagesList[j].IsSelected = true;
}
此处ProgrammingLanguagesList
是observablecollection
,然后我收到错误
Error 8 Argument 1: cannot convert from
'InternRegistration.ViewModel.SelectionItem<string>' to 'string'
这里,dominatorIntern.ProgrammingLanguages是一个存储c,java,c ++等语言的字符串,ProgrammingLanguagesList是一个observablecollection。附带一个例子
如果ProgrammingLanguagesList = {c,java,c#}和dominatorIntern.ProgrammingLanguages = c,java我想要ProgrammingLanguagesList [0] .IsSelected = true;和ProgrammingLanguagesList [1] .IsSelected = true;我怎么能这样做?
答案 0 :(得分:0)
根据您的代码......看起来ProgrammingLanguagesList
是一个InternRegistration.ViewModel.SelectionItem<string>
的数组?
你需要这样的东西......
// replace ??? on the next line with your SelectionItem<string>'s property that
// holds the language name.
var vmLanguageNameProp = ProgrammingLanguagesList[j].???
if ( dominatorIntern.ProgrammingLanguages.Contains(vmLanguageNameProp )
{
ProgrammingLanguagesList[j].IsSelected = true;
}
另请注意,看起来您正在为每次循环迭代进行数据库调用以获取计数...如果确实存在正在发生的事情,您绝对不希望这样做。