I got a treeview data loaded from a XML file. I want to perform a search when the user types something in the textbox. Is that the right way of doing it?? I just want to filter the data. Please show me some example.
The below code is not working.
textBox1.Enter += new EventHandler(txtSearch_TextChanged);
private void txtSearch_TextChanged(object sender, EventArgs e)
{
foreach (TreeNode node in this.treeView1.Nodes)
{
if (node.Text.ToUpper().Contains(this.textBox1.Text.ToUpper()))
{
treeView1.SelectedNode = node;
break;
}
}
you need to register to the text changed event: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.textchanged.aspx
and for finding the specific node use:
mode details here: http://msdn.microsoft.com/en-us/library/system.windows.forms.treenodecollection.find