在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;
}

解决方案 »

  1.   

    怎么给listBox的value负值,我用代码实现,xiexie
      

  2.   

    private string[][] lists={
     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]);
    }
    }
    }
      

  3.   

    cpio(就这么简单)谢谢你,你的方法确实很好,支持你,可是数组定义,我还要和城市联系起来,所以这样就不好解决了,应该怎么办,是不是通过数据库存储比较好一点。
      

  4.   

    kuya(求知)能把你的类共享吗