Jump to content
Forumu Destekleyenlere Katılın ×
Paticik Forumları
2000 lerden beri faal olan, çok şukela bir paylaşım platformuyuz. Hoşgeldiniz.

TreeList Arama Özelliği


joycode

Öne çıkan mesajlar

Yazdığım kodun son halini paylaşıyorum. Node ve child node'larda arama yapıyor ve bulduklarının hepsini listeye getiriyor.

TreeView _treMultiSelection = new TreeView();

//Using the node.Clone() function works as well...
foreach ( TreeNode node in treMultiSelection.Nodes ) {
_treMultiSelection.Nodes.Add( ( TreeNode )node.Clone() );
}


private void txtFilter_TextChanged_1( object sender, EventArgs e ) {
if ( txtFilter.Text != "" ) {
var query = FindNodeByValue( _treMultiSelection.Nodes, txtFilter.Text.ToUpper() );
if ( query != null ) {
treMultiSelection.Nodes.Clear();
foreach ( TreeNode node in query ) {
treMultiSelection.Nodes.Add( node );
}
treMultiSelection.ExpandAll();
}
}
else {
treMultiSelection.Nodes.Clear();
// Using the node.Clone() function works as well...
foreach ( TreeNode node in _treMultiSelection.Nodes ) {
treMultiSelection.Nodes.Add( ( TreeNode )node.Clone() );
}
}

}
private IEnumerable FindNodeByValue( TreeNodeCollection nodes, string searchstring ) {
foreach ( TreeNode node in nodes ) {
if ( node.Text.Contains( searchstring ) )
yield return node;
else {
foreach ( var subNode in FindNodeByValue( node.Nodes, searchstring ) )
yield return subNode;
}
}
}
Link to comment
Sosyal ağlarda paylaş

×
×
  • Yeni Oluştur...