TreeView模糊查询

来源:互联网 发布:能打开db数据库的软件 编辑:程序博客网 时间:2024/06/06 18:42

   1. 方法

 private int TreeviewFindWithText(string text,int startindex)        {            for (int i = startindex; i < treeView1.Nodes[0].Nodes.Count; i++)            {                if (treeView1.Nodes[0].Nodes[i].Text.Trim().Contains(text))                {                    return i;                                                      }               // return -1;            }            return -1;        }

2.定义全局变量 

  int findindex= 0;

3.使用

click方法中

  string strText = this.textBox1.Text.Trim();                ListViewItem lvItem = this.listView1.FindItemWithText(strText, true, iSearchIndex);                if (lvItem != null)                {                    lvItem.Selected = true;                    this.listView1.TopItem = lvItem;                    iSearchIndex = lvItem.Index + 1;                    if (iSearchIndex >= this.listView1.Items.Count)                    {                      <pre name="code" class="csharp">  iSearchIndex = 0;

} } else { iSearchIndex = 0; }

Text_changed事件中

iSearchIndex = 0;


0 0
原创粉丝点击