想在listbox中模糊查找怎么实现呀!
就象msdn的搜索一样的...
谢谢

解决方案 »

  1.   

    一个比较笨的方法,每次输入新的字符,就遍历ListBox中的项目,判断开头字符是否相符,有相符的就定位到第一个相符的项目,思路大致如此,不过这样效率很低,如果项目很多的话,速度会很慢,优化的算法就自己考虑了。
      

  2.   

    for each遍历listbox所有选项
    然后在循环中使用indexof函数下边是indexof的介绍!
    报告指定的 String 在此实例中的第一个匹配项的索引。[Visual Basic]
    Overloads Public Function IndexOf( _
       ByVal value As String _
    ) As Integer
    [C#]
    public int IndexOf(
       string value
    );
    [C++]
    public: int IndexOf(
       String* value
    );
    [JScript]
    public function IndexOf(
       value : String
    ) : int;
    参数
    value 
    要查找的 String。 
    返回值
    如果找到该字符,则为 value 的索引位置;如果未找到该字符,则为 -1。如果 value 为 Empty,则返回值为 0。
      

  3.   

    for(int i=YourListBox.length-1;i>=0;i--)//作循环,从最后一个到最前一个
    //因为从前向后删除的话,后边的index会发生变化!
    {
    if(YourListBox.items[i].toString().IndexOf(YouSearchString)<1)
    //如果没有要找的字符串,就remove他
    //如果找到该字符,则为 value 的索引位置;如果未找到该字符,则为 -1。
    //如果 value 为 Empty,则返回值为 0。
    {
    YourListBox.items.remove(i);
    }
    }