首页 > vb.net > 组合框内的项目没有显示

组合框内的项目没有显示 (Items inside the combobox not showing)

2019-03-01 vb.net

问题

我试图在VB中的组合框中添加一些项目,但是当我将项目添加到组合框的单击事件处理程序并运行代码时,添加的项目不会显示。

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    Me.Refresh()
    ComboBox1.Items.Clear()
    ComboBox1.Items.Add("Mondad")
    ComboBox1.Items.Add("Tuesday")
    ComboBox1.Items.Add("Wenesday")
    ComboBox1.SelectedIndex = 1
End Sub

我的意思是组合框内没有任何显示。

解决方法

只需将此添加到您的代码我认为它将起作用

Private Sub ComboBox1_Click(sender As Object, e As EventArgs) Handles ComboBox1.Click
        ComboBox1.Items.Clear()
        ComboBox1.Items.Add("Mondad")
        ComboBox1.Items.Add("Tuesday")
        ComboBox1.Items.Add("Wenesday")
        ComboBox1.SelectedIndex = 1
    End Sub

希望能帮助到你

问题

I am trying to add some items to a combo box in VB, but when I add the items to the click event handler of the combo-box, and run the code, the items added do not show.

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    Me.Refresh()
    ComboBox1.Items.Clear()
    ComboBox1.Items.Add("Mondad")
    ComboBox1.Items.Add("Tuesday")
    ComboBox1.Items.Add("Wenesday")
    ComboBox1.SelectedIndex = 1
End Sub

I mean nothing shows inside the combo-box.

解决方法

Just add this to your code i think it will work

Private Sub ComboBox1_Click(sender As Object, e As EventArgs) Handles ComboBox1.Click
        ComboBox1.Items.Clear()
        ComboBox1.Items.Add("Mondad")
        ComboBox1.Items.Add("Tuesday")
        ComboBox1.Items.Add("Wenesday")
        ComboBox1.SelectedIndex = 1
    End Sub

hope it helps

相似信息