开发者

Linq Object as ComboBox DataSource

开发者 https://www.devze.com 2023-02-01 16:09 出处:网络
I have a ComboBox being bind to LINQ object as below. Dim LearnTypeList = c开发者_如何学JAVAontext.LearnTypes.OrderBy(Function(a) a.LearnType).ToList()

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消