vb.net 如何获取组合框下拉列表中的每个值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26521449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 18:23:41  来源:igfitidea点击:

How to get each value in combobox dropdown list?

vb.netforeachcombobox

提问by Ke Vin

How to get each value in combobox dropdown list?

如何获取组合框下拉列表中的每个值?

here is what i try

这是我尝试的

        For Each obj In cbComboBox.Items
        MessageBox.Show(obj.ToString)
    Next

it just showing up the combobox datasource object, it not showing, what is in the items

它只是显示组合框数据源对象,它没有显示项目中的内容

回答by OneFineDay

Is there a class type to extract? This is an objectCollection. When you add things to them there are stored as objects. So cast the obj back to it's type and then proceed.

是否有要提取的类类型?这是一个objectCollection. 当你向它们添加东西时,它们被存储为对象。所以将 obj 转换回它的类型,然后继续。

For Each obj In cbComboBox.Items
    Dim item = TryCast(obj, {the object type or class})
    If Not item Is Nothing Then
      'use the item as it is converted correctly
    End If
Next

回答by Pete

For each item As DataRowView In cbComboBox.Items
        msgbox(item.Row("valuecolumnname"))
    next

Just thought i would add this also as another option.

只是想我也会添加这个作为另一种选择。