c# winform treeView从access导入树节点问题,新手求大神修改代码!!
private void Main_Load(object sender, EventArgs e){
//打开后导入treeView
DataTable dt = OleHelp.ExecuteDataSet(OleHelp.ConnectionStringLocalTransaction, CommandType.Text, "select * from TBL_Groups", null).Tables[0];
filltree(treeView1.Nodes[0], dt, 0);
}
/// <summary>
/// 递归添加树节点方法
/// </summary>
/// <param name="tn">要添加子节点的当前节点</param>
/// <param name="dt">数据表</param>
/// <param name="id">当前节点id</param>
///
public void filltree(TreeNode tn, DataTable dt, int id)
{
string str = " pid = " + id;
DataRow[] dr = dt.Select(str, "id");
if (dr.Length == 0) return;
TreeNode ztn;
for (int i = 0; i < dr.Length; i++)
{
ztn = new TreeNode(dr[i]["gkname"].ToString(), 1, 1);
ztn.Tag = dr[i]["id"].ToString();
tn.Nodes.Add(ztn);
filltree(ztn, dt, Convert.ToInt16(ztn.Tag));
}
}
添加了数据,父节点和子节点在不同的两张表中,再次打开后只导入了第一层节点,子节点该怎么导入呢?求教额!!