2楼的谢谢了 你那样改 总分类是和一级节点处于同一级的 我已经自己解决问题了
代码如下,希望给碰到同样问题的朋友参考下
private void bindInfo()
{
TreeView1.Nodes.Clear();
TreeNode root = null;
TreeNode node = null;
TreeNode lc = new TreeNode("楼层","-1");
lc.ExpandAll();
List<FloorType> list = new Select().From<FloorType>().OrderAsc(FloorType.Columns.FatherID).ExecuteTypedList<FloorType>();
StringBuilder sb_str = new StringBuilder();
foreach (FloorType st in list)
{
if (st.FatherID == 0)
{
root = new TreeNode();
root.Value = st.Id.ToString();
root.Text = st.TypeName+st.TypeItem;
root.ToolTip = "一级";
root.ExpandAll();
foreach (FloorType st1 in list)
{
if (st1.FatherID == st.Id)
{
sb_str.Remove(0, sb_str.ToString().Length);
node = new TreeNode();
node.Value = st1.Id.ToString();
node.Text = sb_str.Append(st1.TypeName).ToString();
node.ToolTip = "二级";
root.ChildNodes.Add(node);
}
}
lc.ChildNodes.Add(root);
}
}
TreeView1.Nodes.Add(lc);
} |