文本框中输入内容,listbox快速查询定位。

解决方案 »

  1.   

    string s = textBox1.Text;
    char c = s.Length > 0 ? '\0' : s[0];foreach(Control item in listBox1.Items){
      string f = item.Text;
      if(f[0] == c && f.StartWith(s)) {
        Select(item);
        break;
    }
    }
      

  2.   

    int index = listBox1.FindStringExact("");
      

  3.   

    C# 复制代码 
    private void FindMySpecificString(string searchString)
    {
       // Ensure we have a proper string to search for.
       if (searchString != string.Empty)
       {
          // Find the item in the list and store the index to the item.
          int index = listBox1.FindStringExact(searchString);
          // Determine if a valid index is returned. Select the item if it is valid.
          if (index != ListBox.NoMatches)
             listBox1.SetSelected(index,true);
          else
             MessageBox.Show("The search string did not find any items in the ListBox that exactly match the specified search string");
       }
    }