主窗體部分**
/// /// 遍歷樹節點,並將節點存入list集合中
///
///
///
public void getallnodes(treenodecollection nodecollection, listnodelist)
}/// /// 查詢
///
///
///
private void btnfolder_click(object sender, eventargs e)
treeviewquery frm = new treeviewquery(this);
frm.showintaskbar = false;
frm.show(this);
}查詢窗體**
private folderfrom parentfrm;
private string lastfindstring; //記錄上一次查詢的文字
private int lastfindcount; //記錄上一次查詢的標記
private listnodelist = new list(); //記錄所有的樹節點
public treenode node = null; //記錄查詢到的節點
private bool isup = false; //是否向上查詢
public treeviewquery ()
public treeviewquery (folderfrom frm)
#region methods
/// /// 模糊匹配(向下查詢)
///
///
///
private int findnodepartdown(string inputtext, int startcount)
}return -1;
}/// /// 模糊匹配(向上查詢)
///
///
///
private int findnodepartup(string inputtext, int startcount)
//for (int i = nodelist.count - 1; i > startcount; i--)
for (int i = startcount; i >= 0; i--)
}return -2;
}/// /// 全字匹配查詢(向下查詢)
///
/// 查詢的內容
/// 起始位置
///
private int findnodealldown(string inputtext, int startcount)
}return -1;
}/// /// 全字匹配查詢(向上查詢)
///
/// 查詢的內容
/// 起始位置
///
private int findnodeallup(string inputtext, int startcount)
}return -1;
}#endregion
#region events
/// /// 取消
///
///
///
private void btnclose_click(object sender, eventargs e)
/// /// 窗體載入
///
///
///
private void treeviewquery_load(object sender, eventargs e)
/// /// 當文字框不為空時啟用查詢按鈕
///
///
///
private void txtinputtext_textchanged(object sender, eventargs e)
else
}/// /// 查詢下乙個
///
///
///
private void btnquerynext_click(object sender, eventargs e)
else
isup = true;
}else
else
isup = false;}}
else
else
isup = true;
}else
else
isup = false;}}
if (lastfindcount == -1) //判斷是否找到節點
else if (lastfindcount == -2) //判斷是否找到節點
node = nodelist[lastfindcount];
parentfrm.tvfolder.selectednode = node; //選中查詢到的節點
parentfrm.tvfolder.focus();
}
C TreeView 節點查詢
主窗體部分 遍歷樹節點,並將節點存入list集合中 public void getallnodes treenodecollection nodecollection,listnodelist 查詢 private void b ir click object sender,eventargs e ...
C TreeView查獲節點並選中節點
在乙個專案中用到了treeview,但是每次重新整理treeview的資料之後,所有的節點都會摺疊起來 非常影響使用者體驗,使用下面的方法可以解決這個問題 string lastselectnode 先儲存當前選中的節點的key lastselectnode treeview1.selectedno...
C TreeView樹節點上下移動
上移 private void tsbmoveup click object sender,eventargs e folder model new folder treenode node tv tree.selectednode 獲得選中節點的值 model.folderid node.tag....