关于combobox的小问题 有个combobox我想设置它的text属性为<请选择状态>,这个combobox包括以绑定的两个选项比如On和Off,且这个combobox我要设置成 DropDownList 的,不能让用户修改选项。请问各位怎么实现呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 comboBox1.DropDownStyle = ComboBoxStyle.DropDownList; comboBox1.Items.Add("on"); comboBox1.Items.Add("off"); comboBox1.Items.Insert(0, "请选择"); comboBox1.SelectedIndex = 0; Form_Load()里:ComboBox1.Items.Insert(0,"<请选择状态>");ComboBox1.SelectedIndex=0;SelectedChange()事件里:if (comboBox1.SelectedIndex > 0 && comboBox1.SelectedItem.ToString() != "<请选择状态>")comboBox1.Items.RemoveAt(0); 难道你是想这样?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){} 首先对大家表示感谢,其次以上答案都不正确,没有达到效果1楼的答案,<请选择状态>还是做为一个选项存在了,我希望要的是,它作为这个combobox的Text,在选项里是不存在的。 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); } } 如何用C#中的Process类实现telnet远程登录交换机并将一些命令传给交换机执行? for循环嵌套IF,和IF里嵌套for循环 效率的比较 菜鸟寻求帮助~~用C#做遥感影像的更新 当前上下文中不存在名称“ConfigurationManager” 关于winforms 的richtextbox使用 如何设置桌面图片居中显示? C++到C# C#里如何像C++那样传递一个数组的地址 哪位大侠使用过SQL CE? 安装DONET时的问题? C#中string转换成double的方法是什么?help! c# combox 显示一个值,但是对应的另一个值 C#计算器程序解释寻求
comboBox1.Items.Add("on");
comboBox1.Items.Add("off");
comboBox1.Items.Insert(0, "请选择");
comboBox1.SelectedIndex = 0;
ComboBox1.Items.Insert(0,"<请选择状态>");
ComboBox1.SelectedIndex=0;SelectedChange()事件里:
if (comboBox1.SelectedIndex > 0 && comboBox1.SelectedItem.ToString() != "<请选择状态>")
comboBox1.Items.RemoveAt(0);
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)
{}
{
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);
}
}