本帖最后由 soundofsea 于 2009-07-12 22:10:50 编辑

解决方案 »

  1.   

           public static void AddNodes(TreeView tv, DataTable dt, string text,
                string value, string url, string rootselect, string rootselectvalue,
                int rootindex, string childselect, string childselectvalue, string ordervalue, string ovalue)
            {            DataRow[] root = dt.Select(rootselect + "=" + rootselectvalue, ordervalue + " " + ovalue);
                for (int i = 0; i < root.Length; i++)
                {
                    TreeNode tn = new TreeNode();
                    tn.Text = root[i][text].ToString();
                    tn.SelectAction = TreeNodeSelectAction.None;
                    tn.Value = root[i][value].ToString();
                    tv.Nodes.AddAt(rootindex, tn);
                    if (i != root.Length - 1)
                    {
                        tn.Expanded = false;
                    }                addchilid(dt, text, value, url, childselect, childselectvalue, tn, root[i], ordervalue, ovalue);
                }
            }
            private static void addchilid(DataTable dt, string text,
                string value, string url, string childselect,
                string childselectvalue, TreeNode ftn, DataRow fdr, string ordervalue, string ovalue)
            {
                DataRow[] child = dt.Select(childselect + "=" + fdr[childselectvalue].ToString(), ordervalue);
                for (int j = 0; j < child.Length; j++)
                {
                    TreeNode ctn = new TreeNode();
                    ctn.Text = child[j][text].ToString();
                    ctn.NavigateUrl = child[j][url].ToString();
                    ctn.Value = child[j][value].ToString();
                    ftn.ChildNodes.Add(ctn);                addchilid(dt, text, value, url, childselect, childselectvalue, ctn, child[j], ordervalue, ovalue);
                }
            }
      

  2.   


            TreeNode TN = new TreeNode();
            TN.Text = DS.Tables[0].Rows[i][1].ToString();
            TN.Value = DS.Tables[0].Rows[i][0].ToString();
            TreeView1.Nodes.Add(TN);
    生成节点后,我如何才能获取本节点的 IndexOf 的索引值?
    我的子节点在添加时需要Nodes[父节点值]TreeView1.Nodes[0].ChildNodes.Add(TN);