数据库1:
id      (Name)名称       (parentId)父节点
1         公司                null
2          投宿                1
3           申报               1
数据库2
id         (name)名称          Typeid
1              投宿部门           2
2              申报请假            3要显示的形状是:
公司
  投宿
    投宿部门
  申报
    申报请假

解决方案 »

  1.   

    自己终于搞定拉
    public void ViewWorkFlowTypeTree(TreeNode tn)
    {
    int i;
    // 空节点时创建根节点,自定义根节点
    if(tn == null)
    {
    int flag=0;//0:标志不存在根节点,否则存在根节电
    treeWorkFlowType.Nodes.Clear();
    for(i = 0 ; i < c_ConfigDataSet.Tables["WorkFlowType1"].Rows.Count ; i ++)
    {
    if(c_ConfigDataSet.Tables["WorkFlowType1"].Rows[i]["ParentId"].ToString() == "")
    {
    flag=flag+1;
    TreeNode tmp = new TreeNode(c_ConfigDataSet.Tables["WorkFlowType1"].Rows[i]["CatalogName"].ToString());
    string[] NodeTag = new string[] {c_ConfigDataSet.Tables["WorkFlowType1"].Rows[i]["CatalogId"].ToString(), "一级节点"};
    tmp.Tag = NodeTag;
    treeWorkFlowType.Nodes.Add(tmp);
    }
    }
    if(flag==0)
    {
    MessageBox.Show("您的系统还没有进行初始化,请先初始化!");
    FrmNewWorkFlowType frmType = new FrmNewWorkFlowType();  if (frmType.ShowDialog() == DialogResult.OK) 

    SqlConnection conn = new SqlConnection(this.c_ConnectionString);
    string strSql = "insert into WFType(CatalogId,CatalogName,ParentId)  values( 8, '"+frmType.txtFlowType.Text+"',null)";
    SqlCommand cmd = new SqlCommand(strSql,conn);
    cmd.CommandType = CommandType.Text;
    conn.Open();
    cmd.ExecuteNonQuery();
    conn.Close();
    }
    ConfigSync();
    ViewWorkFlowTypeTree(null);
    return;
    }
    // 循环递归创建树
    for(i = 0 ; i < treeWorkFlowType.Nodes.Count ; i ++)
    {
    ViewWorkFlowTypeTree(treeWorkFlowType.Nodes[i]);
    }
    }
    else // 节点非空为递归调用
    {
    for(i = 0 ; i <c_ConfigDataSet.Tables["WorkFlowType1"].Rows.Count ; i ++)
    {
    //MessageBox.Show(((string[])(tn.Tag))[0].ToString() + c_ConfigDataSet.Tables["WorkFlowType1"].Rows[i]["parentid"].ToString());
    if(((string[])(tn.Tag))[0].ToString() == c_ConfigDataSet.Tables["WorkFlowType1"].Rows[i]["parentid"].ToString())
    //if(tn.Tag.ToString() == c_ConfigDataSet.Tables["WorkFlowType1"].Rows[i]["parentid"].ToString())
    {
    int vv = c_ConfigDataSet.Tables["WorkFlowType1"].Rows.Count;
    TreeNode tmp = new TreeNode(c_ConfigDataSet.Tables["WorkFlowType1"].Rows[i]["catalogname"].ToString());
    string[] NodeTag = new string[] {c_ConfigDataSet.Tables["WorkFlowType1"].Rows[i]["catalogId"].ToString(), "二级节点"};
    tmp.Tag = NodeTag;

    tn.Nodes.Add(tmp);
    }
    }
    for(i = 0 ; i < tn.Nodes.Count ; i ++)
    {
    fountleaf(tn.Nodes[i]);

    }
    }
    }