TreeNodeCollection是treeview1的结点集合,dataset 中数据的字段,TreeNodeKind是T或F public void DBToTreeNode(TreeNodeCollection TNColl, string ZhiDuAN, string TreeNodeKind)
        {
            for (int i = 0; i < DT.Rows.Count; i++)
            {
                bool Bool_UseFlag;
                if ( DT. Rows[i]["USE_Flag"].ToString() == "F")
                {
                    Bool_UseFlag = true;                }
                else
                {
                    Bool_UseFlag = false;
                }
                if (DT.Rows[i][ZhiDuAN].ToString().Split('^').Length == 2)
                {
                    if (DT.Rows[i][ZhiDuAN].ToString().Split('^').GetValue(0).ToString() == TreeNodeKind && DT.Rows[i][ZhiDuAN].ToString().Split('^').Length == 2) ;//控件名称
                    {
                        if (!treeView1.Nodes.ContainsKey(DT.Rows[i][ZhiDuAN].ToString().Split('^').GetValue(1).ToString()))
                        {
                            TNColl.Add(DT.Rows[i][ZhiDuAN].ToString().Split('^').GetValue(1).ToString(), DT.Rows[i][ZhiDuAN].ToString().Split('^').GetValue(1).ToString());
                            TNColl[DT.Rows[i][ZhiDuAN].ToString().Split('^').GetValue(1).ToString()].ToolTipText = DT.Rows[i][ZhiDuAN].ToString().Split('^').GetValue(0).ToString();
                            TNColl[DT.Rows[i][ZhiDuAN].ToString().Split('^').GetValue(1).ToString()].Checked = Bool_UseFlag;
                            DBToTreeNode(TNColl[DT.Rows[i][ZhiDuAN].ToString().Split('^').GetValue(1).ToString//递归调用()].Nodes, "Sub1_Menu", "一级子菜单");
                        }
                    }
                }
            }
        }红色的那行出现未处理的“System.StackOverflowException”类型的异常出现在 mscorlib.dll 中。

解决方案 »

  1.   

        public void DBToTreeNode(TreeNodeCollection TNColl, string ZhiDuAN, string TreeNodeKind)
            {
                for (int i = 0; i < DT.Rows.Count; i++)
                {
                    bool Bool_UseFlag;
                    if (DT.Rows[i]["USE_Flag"].ToString() == "F")
                    {
                        Bool_UseFlag = true;                }
                    else
                    {
                        Bool_UseFlag = false;
                    }
                    string temp = DT.Rows[i][ZhiDuAN].ToString();
                    if (temp.Split('^').GetValue(0).ToString() == TreeNodeKind && temp.Split('^').Length == 2)//控件名称 
                    {
                        if (!TNColl.ContainsKey(temp.Split('^').GetValue(1).ToString()))
                        {
                            TNColl.Add(temp.Split('^').GetValue(1).ToString(), temp.Split('^').GetValue(1).ToString());
                            TNColl[temp.Split('^').GetValue(1).ToString()].ToolTipText = temp.Split('^').GetValue(0).ToString();
                            TNColl[temp.Split('^').GetValue(1).ToString()].Checked = Bool_UseFlag;
                            DBToTreeNode(TNColl[temp.Split('^').GetValue(1).ToString()].Nodes, "Sub1_Menu", "一级子菜单");
                        }
                    }            }
            }
    怎么改呀,,