Linq Object as ComboBox DataSource
I have a ComboBox being bind to LINQ object as below.
Dim LearnTypeList = c开发者_如何学JAVAontext.LearnTypes.OrderBy(Function(a) a.LearnType).ToList()
dlLearnedAbout.DataSource = LearnTypeList
dlLearnedAbout.DisplayMember = "LearnType"
dlLearnedAbout.ValueMember = "LearnType"
I am not able to use Index of Items to find Item with matching text as below .
MessageBox.Show(dlLearnedAbout.Items.IndexOf("Website"))
This always returns -1 even if its there inside the table and dropdown.Is it because the Item bound to the Dropdown is of type "LearnTypes ?
IndexOf("Website") is looking through the list for an item of type String. your list doesn't contain strings though - it contains objects of whatever type you have in context.LearnTypes. that's why you are getting -1 (aka item not found)
精彩评论