Populate N-Level TreeView from multiple tables using C# in Windows Application

Last Reply 8 months ago By Jesus

Posted 8 months ago

How to Populate treeview from 2 SQL tables with n Levels

on this link is only one table, I need same thing from 3 tables.

Populate Multi-Level (N-Level) TreeView using C# and VB.Net in Windows Application

this is the code I use to load data to the treeview, this is working well enougth, but is only for 2 layer.

        private void llenarTreeView()
        {
            DataTable dt = new DataTable();
            dt = CADArea.GetData();
            foreach (DataRow dr in dt.Rows)
            {
                parentNode = treeView1.Nodes.Add(dr["Area"].ToString());
                PopulateTreeView(Guid.Parse(dr["IdArea"].ToString()), parentNode);
            }
            treeView1.ExpandAll();
        }
 
        private void PopulateTreeView(Guid IdArea, TreeNode parentNode)
        {
            DataTable dtble = new DataTable();
            dtble = CADMaquinas.SelectMaquinasbyIdArea(IdArea);
            TreeNode childNode;
            foreach (DataRow dr in dtble.Rows)
            {
                if (parentNode == null)
                    childNode = treeView1.Nodes.Add(dr["Maquina"].ToString());
                else
                    childNode = parentNode.Nodes.Add(dr["Maquina"].ToString());
                PopulateTreeView(Guid.Parse(dr["IdMaquina"].ToString()), childNode);
            }
        }

 

This question does not have replies that have been liked.