CodeKicks.com
Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Tuesday, October 03, 2006

Loading a TreeView control with Database records using ADO.NET

Loading a TreeView control with Database records using ADO.NET

private void loadtreeview()
        { 
            // loading a TreeView control from ADO //
            TreeNode nodeFirstRecord, nodeSecondRecord;
            foreach (DataRow rowMyfirstRow in ds_MyDataSet.MyTable.Rows)
           {
                nodeFirstRecord = 
                   new TreeNode(rowMyfirstRow["MyColumn"].ToString());
                treeView1.Nodes.Add(nodeFirstRecord);
                foreach(DataRow rowMySecondRow in 
                    rowMyfirstRow.GetChildRows("MyRelation"))
                {
                    nodeSecondRecord =
                        new TreeNode(rowMySecondRow["MyColumn"].ToString());
                    nodeFirstRecord.Nodes.Add(nodeSecondRecord);
                }
            }
        }

Post a Comment