Search a Node in TreeView

Dec 18 2007 4:55 AM
Hello everybody...

I have to develop a button for a search node in treeview, on this site I found this code, but when I try it on my environment
tn.Length is always 0...
can anyone help me please???!!!

private void cerca_Click(object sender, EventArgs e)
        {
            ResetPMInfo();
            ResetForm();
         
            string TextSQL = "SELECT * FROM PM_TREE_VIEW WHERE TYPE=1 AND CODE_PREFIX like '%" + textCerca.Text + "%'";
            DBHandler dbHand = new DBHandler();
            CodePrefix = (string)dbHand.GetField(TextSQL, "CODE_PREFIX");
            TreeNode Node = new TreeNode();
            Node.Text = CodePrefix;                 

//the code took from this site
            try
            {

                TreeNode[] tn = PlannedMaintenance_MainTreeView.Nodes[0].Nodes.Find(Node.Text, true);

                for (int i = 0; i < tn.Length; i++)
                {

                    PlannedMaintenance_MainTreeView.SelectedNode = tn[i];

                    PlannedMaintenance_MainTreeView.SelectedNode.BackColor = Color.Blue;

                }

            }

            catch { }
            this.Cursor = Cursors.AppStarting;
            LoadPMList();
            this.Cursor = Cursors.Default;
        }