大马资讯论坛 - 马来西亚中文资讯平台

 找回密码
 注册
搜索
打印 上一主题 下一主题

C# ComboBox in DropDownList style Set Text加入String

[复制链接]
跳转到指定楼层
1#
发表于 2011-8-17 22:11:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
实现在DropDownList添加初始化值,代码如下供参考。
  1. comboBox.Text = "Select Customer";
复制代码
首先你可以在form load时,添加Select Customer。
当on click时,把它拿掉即可。
  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3.     if (!comboBox1.Items.Contains("Select Customer"))
  4.     {
  5.         comboBox1.Items.Add("Select Customer");
  6.     }

  7.     comboBox1.Text = "Select Customer";
  8. }

  9. private void comboBox1_DropDown(object sender, EventArgs e)
  10. {
  11.     if (comboBox1.Items.Contains("Select Customer"))
  12.         comboBox1.Items.Remove("Select Customer");
  13. }
复制代码

手机版|大马资讯论坛  

GMT+8, 2024-5-4 18:31 , Processed in 0.016430 second(s), 13 queries , File On.

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表