如题,我在数据库中建立了表,首字母和相应的汉字都有,如何在程序中让combox输入首字母显示出汉字呢,就像12306订票系统一样,在站台名中输入首字母出现汉字。
因为你已经有你的数据库表,所以可以参考一下根据拼音首字母进行过滤的combobox
关于扩展可以支持拼音首字母查询的ComboBox自定义控件,可以参考支持拼音首字母查询的ComboBox
参考:http://download.csdn.net/download/icysky0605/4373065
http://www.cnblogs.com/yazdao/archive/2011/06/04/2072488.html。可以试下。
[link text]链接1
楼主应该说的是 TextBox ??? 数据库建立两个字段,一个 汉子名字字段,一个拼音首字母匹配的字段 , 然后在 绑定输入…………额,直接上代码你看看
private List stationList = new List();
if (this.Text.Length > 0)
{
foreach (station s in te.station.Where(c => c.station_reserved1.StartsWith(this.Text)))
stationList.Add(s);
foreach (station s in te.station.Where(c => c.station_name.StartsWith(this.Text)))
stationList.Add(s);
}
if (stationList.Count > 0)
{
if (listBox == null)
{
listBox = new ListBox();
listBox.Visible = false;
listBox.Width = this.Width;
listBox.Height = 100;
Control parent = this.Parent;
while (parent.Parent != null)
parent = parent.Parent;
listBox.Parent = parent;
listBox.Location = new Point(this.Location.X, this.Location.Y + this.Height);
listBox.Click += new EventHandler(listBox_Click);
}
listBox.DataSource = stationList;
listBox.ValueMember = "station_code";
listBox.DisplayMember = "station_name";
listBox.Visible = true;
listBox.BringToFront();