有个combobox我想设置它的text属性为<请选择状态>,这个combobox包括以绑定的两个选项比如On和Off,且这个combobox我要设置成 DropDownList 的,不能让用户修改选项。请问各位怎么实现呢?

解决方案 »

  1.   

    comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
                comboBox1.Items.Add("on");
                comboBox1.Items.Add("off");
                comboBox1.Items.Insert(0, "请选择");
                comboBox1.SelectedIndex = 0;
      

  2.   

    Form_Load()里:
    ComboBox1.Items.Insert(0,"<请选择状态>");
    ComboBox1.SelectedIndex=0;SelectedChange()事件里:
    if (comboBox1.SelectedIndex > 0 && comboBox1.SelectedItem.ToString() != "<请选择状态>")
    comboBox1.Items.RemoveAt(0);
      

  3.   

    难道你是想这样?
    this.comboBox1.Text = "<请选择>";
    this.comboBox1.Items.Add("On");
    this.comboBox1.Items.Add("Off");
    this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {}
      

  4.   

    首先对大家表示感谢,其次以上答案都不正确,没有达到效果1楼的答案,<请选择状态>还是做为一个选项存在了,我希望要的是,它作为这个combobox的Text,在选项里是不存在的。
      

  5.   

         private void Form1_Load(object sender, EventArgs e)
            {
                comboBox1.DrawMode = DrawMode.OwnerDrawFixed;
      
            }
            private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
            {
                ComboBox _ComboBox = (ComboBox)sender;
                e.DrawBackground();
                e.DrawFocusRectangle();
                if (e.Index == -1)
                {
                    e.Graphics.DrawString("请选择", e.Font, new SolidBrush(e.ForeColor), e.Bounds);
                }
                else
                {
                    e.Graphics.DrawString(_ComboBox.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds);
                }
            }