vb.net VB .NET COMBOBOX ValueMember

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13398251/
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 11:08:52  来源:igfitidea点击:

VB .NET COMBOBOX ValueMember

databasevb.netcomboboxvaluemember

提问by Tom Konski

Hi guys I have problem with ValueMember. Look on code :

大家好,我有 ValueMember 的问题。查看代码:

   conn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & _
"c:\magazyn.mdb"
    ' Try
    conn.Open()

    da2 = New OleDbDataAdapter(sql1, conn)

    da2.Fill(ds2)
    ' DataGridView1.DataSource = ds.Tables("Nazwa")
    ' DataGridView1.Update()
    ComboBox4.DataSource = Nothing

    ComboBox4.DataSource = ds2.Tables(0)

    ComboBox4.ValueMember = Nothing
    ComboBox4.DisplayMember = "Nazwa_Towaru"
    ComboBox4.ValueMember = "Kod_Towaru"

    MessageBox.Show(ComboBox4.Text + "-" + ComboBox4.ValueMember)

    ' Catch ex As Exception
    'MessageBox.Show("Brak pod??czonej bazy/problem z pod??czeniem do bazy")
    '  Finally
    conn.Close()
    '  End Try

MessageBox should show me somthing like this : Graphic Card - 123ASD first element is "Nazwa_Towaru" second is "Kod_Towaru" but MB show me somthing like this : Graphic Card - "Kod_Towaru". First time I think "Kod_Towaru" column in DATASET is empty but i check this and column is with data .

MessageBox 应该向我展示这样的东西:图形卡 - 123ASD 第一个元素是“Nazwa_Towaru”,第二个是“Kod_Towaru”,但 MB 向我展示这样的东西:显卡 - “Kod_Towaru”。我第一次认为 DATASET 中的“Kod_Towaru”列是空的,但我检查了这一列,并且该列包含数据。

I have also another ComboBox with this same code and its work great so why this one not. ALL variables are local so they no colidate.

我还有另一个具有相同代码的 ComboBox,它的工作非常好,为什么不使用这个。所有变量都是局部变量,因此它们没有共存。

回答by Serge Bollaerts

I guess that ComboBox4.SelectedIndex = -1. After binding your combo box with a data source, set the selected index to 0 (if there are data in the combo box)

我猜 ComboBox4.SelectedIndex = -1。将你的组合框与数据源绑定后,将选中的索引设置为0(如果组合框中有数据)

Serge

哔叽