How to show text in combobox when no item selected?

前端 未结 16 1357
太阳男子
太阳男子 2020-11-30 06:39

C# & .Net 2.0 question (WinForms)

I have set of items in ComboBox and non of them selected. I would like to show a string on combo \"Pl

16条回答
  •  野性不改
    2020-11-30 07:13

    If none of the previous solution are working for you, why not add some validation on combobox something like,

        var orginalindex = 0;
    
        private void comboBox1_SelectedItemChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 0)
            {
                comboBox1.Text = "Select one of the answers";
                comboBox1.SelectedIndex = comboBox1.SelectedIndex;
            }
            else
            {
                orginalindex = comboBox1.SelectedIndex;
            }
        }
    

提交回复
热议问题