使用按钮 vb.net 更改组合框选定的项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19756830/
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
Change combobox selected item with button vb.net
提问by user2950509
I wanted to know if it is possible to have two buttons that change the currently selected item of a combobox "up one" or "down one". So I would have two buttons: next and back, and when you click on next, the selected item in the combobox will change to the one lower in the list (1 -> 2), and if you click back, it will return to the previous item (1 <- 2). Thanks in advance,
我想知道是否可以有两个按钮来更改组合框的当前选定项目“向上”或“向下”。所以我会有两个按钮:next 和 back,当你点击 next 时,组合框中的所选项目将更改为列表中较低的项目 (1 -> 2),如果你点击 back,它将返回到前一项 (1 <- 2)。提前致谢,
回答by Idle_Mind
Something like...
就像是...
Private Sub btnUp_Click(sender As System.Object, e As System.EventArgs) Handles btnUp.Click
If ComboBox1.SelectedIndex > 0 Then
ComboBox1.SelectedIndex = ComboBox1.SelectedIndex - 1
End If
End Sub
Private Sub btnDown_Click(sender As System.Object, e As System.EventArgs) Handles btnDown.Click
If ComboBox1.SelectedIndex < ComboBox1.Items.Count - 1 Then
ComboBox1.SelectedIndex = ComboBox1.SelectedIndex + 1
End If
End Sub

