C# 怎么用按钮控制combobox的下拉动作和选择

2024-11-15 01:10:37
推荐回答(1个)
回答1:

界面上放一个combox,3个按钮,分别叫btnUp, btnDown, btnconfirm private void btnUp_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex <=0)
return;
comboBox1.SelectedIndex = comboBox1.SelectedIndex -1;
} private void btnDown_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex >= comboBox1.Items.Count - 1)
return;
comboBox1.SelectedIndex =comboBox1.SelectedIndex +1;
} private void btnConfirm_Click(object sender, EventArgs e)
{
MessageBox.Show(comboBox1.Text);
}