Searching Nodes (need Info after found)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sl1ver
    New Member
    • Mar 2009
    • 196

    Searching Nodes (need Info after found)

    I've implemented search for my nodes if found it will highlight the node yellow but the nodes is programed to show information about it after its selected how will i achieve the information to be shown after the node was found?
    The program doesn't see the highlighted one as selected

    This is my code:
    Code:
     private void ClearRecursive(TreeNode treeNode)
            {
                foreach (TreeNode tn in treeNode.Nodes)
                {
                    tn.BackColor = Color.White;
                    ClearRecursive(tn);
                }
            }
            private void ClearBackColor()
            {
                TreeNodeCollection nodes = tvLocations.Nodes;
                foreach (TreeNode n in nodes)
                {
                    ClearRecursive(n);
                }
            }
            private void FindByText()
            {
                TreeNodeCollection nodes = tvLocations.Nodes;
                foreach (TreeNode n in nodes)
                {
                    FindRecursive(n);
                }
            }
    
            private void FindRecursive(TreeNode treeNode)
            {
                try
                {
                    foreach (TreeNode tn in treeNode.Nodes)
                    {
                        // if the text properties match, color the item
                        if (tn.Text == this.txtFindLoc.Text)
                        
                            tn.BackColor = Color.Yellow;
                            
                      
    
                        FindRecursive(tn);
                    }
                }
                catch (Exception ed)
                {
                    MessageBox.Show("No Macthes were found!");
                }
            }
    
            private void btnFindLoc_Click(object sender, EventArgs e)
            {
                ClearBackColor();
                FindByText();
                string ConnString = Properties.Settings.Default.GriffenConnectionString.ToString();
    
                OleDbConnection Conn = new OleDbConnection(ConnString);
    
    
                string sql = "";
                DataSet dsFillLocation = new DataSet();
    
                {
                    sql = "Select * from qx_AssetLocation where alc__id <> " + tvLocations.SelectedNode.Tag.ToString();
                    OleDbDataAdapter daLocFill = new OleDbDataAdapter(sql.ToString(), Conn);
                    daLocFill.Fill(dsFillLocation, "qx_AssetLocation");
    
                    if (dsFillLocation != null)
                    {
                        cboLocationName.DataSource = dsFillLocation.Tables["qx_AssetLocation"];
                        cboLocationName.DisplayMember = "ALC__DESCRIPTION";
                        cboLocationName.ValueMember = "ALC__ID";
                    }
                }
                
                tvLocations.ExpandAll();
                
                
               
            }
    
            }
    Last edited by tlhintoq; Apr 21 '09, 04:37 AM. Reason: Please use [CODE] ... [/CODE] tags around your code blocks
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    That's because you didn't make it the selected node, you only changed the background color. You need to make it the selected node of the treeview. Jump on MSDN and read the methods for a treeview.

    Comment

    Working...