在listbox的value值中存放地名拼音
private void myListBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar=='w')
{
this.myListBox1.SelectedIndex = GoIndex(this.myListBox1,"W");
}
} private int GoIndex(ListBox lb,string s)
{
for(int i=0;i<lb.Items.Count;i++)
{
USState uss = (USState)lb.Items[i];//我自己定义的类,这样可以取到value值。我的USState中有两个属性 LongName(相当于在listbox中要显示的Text),ShortName(是在value中存的值)
if(uss.ShortName.StartsWith(s))
{
return i;
}
}
return -1;
}
private void myListBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar=='w')
{
this.myListBox1.SelectedIndex = GoIndex(this.myListBox1,"W");
}
} private int GoIndex(ListBox lb,string s)
{
for(int i=0;i<lb.Items.Count;i++)
{
USState uss = (USState)lb.Items[i];//我自己定义的类,这样可以取到value值。我的USState中有两个属性 LongName(相当于在listbox中要显示的Text),ShortName(是在value中存的值)
if(uss.ShortName.StartsWith(s))
{
return i;
}
}
return -1;
}
解决方案 »
- 关于deviceiocontrol使用上的一点疑问
- 100分!在线等!在线结贴!web service 部署到 88端口,不返回数据
- 请问这里的sender是干什么用的?
- 大家帮忙推荐一本ASP.NET入门的书,C#?
- 请教如何在C#(Web页面)中获得confirm的返回值
- 请问这一套程序流程,在专业术语上叫做什么?都涉及了哪方面资料?
- 关于学习c#该不该学asp。net或asp那?
- 部署水晶报表出错:Cannot find KeycodeV2.dll, or invalid keycode
- 团队开发下,如何做数据库的维护呢
- c#代码设置word纸张的大小
- 谁用过c#编程过明华读卡器?
- 来拿分吧,虽然不多.文件路径问题
new string[]{"s","上海","山西","山东","四川"},
new string[]{"c","重庆","青海"},
new string[]{"h","黑龙江","湖北","湖南","河北","河南"}
};private void listBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
this.listBox1.Items.Clear();
for(int i=0;i<lists.Length;i++)
{
if(lists[i][0]==e.KeyCode.ToString().ToLower())
{
for(int j=1;j<lists[i].Length;j++)
this.listBox1.Items.Add(lists[i][j]);
}
}
}