日期:2014-05-18  浏览次数:21196 次

combobox 在未选中任何现象时 文本框中显示提示信息
要求 combobox.DropDownStyle= DropDownList 当 selectedIndex=-1时 显示 "一段文字的",选中其他时正常显示

------解决方案--------------------
你的问题不就像你说的这样解决了嘛

设置ComBox的格式的时候,在窗体的加载事件中编写
C# code

public Form1()
{
    initialize();
    this.combobox.DropDownStyle = DropDownList;
}

------解决方案--------------------
如果是WindowForm,就是要模仿Web网页的灰色效果,所以还要设置一下灰色的效果。单击时候还要去掉文本。
如果是WebForm,当我没说。
------解决方案--------------------
AutoCompleteStringCollection strings = new AutoCompleteStringCollection(); 
strings.Add("123");
strings.Add("456");
...
ComBox.AutoCompleteCustomSource = strings;
ComBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
ComBox.AutoCompleteMode = AutoCompleteMode.Suggest;


------解决方案--------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace password
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.comboBox1.LostFocus += new System.EventHandler(this.comboBox1_LostFocus);
comboBox1.Text = "一段文字";
comboBox1.Items.Add("123");
comboBox1.Items.Add("abc");
}

private void comboBox1_LostFocus(object sender, EventArgs e)
{
if (comboBox1.Text == "")
{
comboBox1.Text = "一段文字";
}
}

private void comboBox1_Click(object sender, EventArgs e)
{
if (comboBox1.Text == "一段文字")
{
comboBox1.Text = "";
}
}
}
}