日期:2014-05-17 浏览次数:20846 次
private void Form1_Load(object sender, EventArgs e)
{
DataRow[] drs = dt.Select("len(ID)=3","ID");
foreach (DataRow dr in drs)
{
TreeNode nodeParent = tv.Nodes.Add(dr["Name"].ToString());
nodeParent.Tag = dr["ID"].ToString();
LoadNode(nodeParent, dt);
}
}
private void LoadNode(TreeNode nodeParent, DataTable dt)
{
string strPID = nodeParent.Tag.ToString();
DataRow[] drs = dt.Select(string.Format("len(ID)={0} and id like '{1}%'",strPID.Length+1,strPID) , "ID");
if (drs != null && drs.Length > 0)
{
foreach (DataRow dr in drs)
{
TreeNode node = nodeParent.Nodes.Add(dr["Name"].ToString());
node.Tag = dr["ID"].ToString();
LoadNode(node, dt);
}
}
}