Change the ComboBox's text field when an item is selected from the drop down list?

前端 未结 2 1268
终归单人心
终归单人心 2021-01-20 14:23

I have a ComboBox on a form. The DropDownStyle property of the ComboBox is set to DropDown, so that the user can select an item from the drop down

2条回答
  •  长发绾君心
    2021-01-20 14:46

    You can try this:

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
      if (comboBox1.SelectedIndex > -1)
      {
        string value = comboBox1.Items[comboBox1.SelectedIndex].ToString().Substring(4);
        this.BeginInvoke((MethodInvoker)delegate { this.comboBox1.Text = value; });
      }
    }
    

提交回复
热议问题