构建TreeView问题

时间:2015-04-24 16:24:39

标签: c# treeview kendo-treeview

我正在尝试构建一个具有3个级别的treeViewItemModel,可能存在或不存在。

像这样:

Tree

从网络服务中,我得到一个包含细分的对象,每个对象都有关于它所属的特征方向的信息。但我似乎无法找到在上述结构中构建树的方法。

以下是我现在的观点:

foreach (wsPAVSegment.segmentOutput segment in gso.segments)
{
    if (!characteristicList.Contains(segment.characteristic.code))
    {
        characteristicList.Add(segment.characteristic.code);
        characteristicTree.Add(new TreeViewItemModel
        {
            Id = segment.characteristic.code,
            Text = segment.characteristic.mediumDescription
        });
    }
}

foreach (wsPAVSegment.segmentOutput segment in gso.segments)
{
    foreach (TreeViewItemModel item in characteristicTree)
    {
        if (item.Id == segment.characteristic.code)
        {
            TreeViewItemModel tvim = new TreeViewItemModel();
            tvim.Id = segment.segment.id;
            tvim.Text = segment.segment.code;

            item.Items.Add(tvim);
        }
    }
}

foreach (wsPAVSegment.segmentOutput segment in gso.segments)
{
    if (!directionList.Contains(segment.direction.code))
    {
        directionList.Add(segment.direction.code);
        directionTree.Add(new TreeViewItemModel
        {
            Id = segment.direction.code,
            Text = segment.direction.mediumDescription,
            Items = characteristicTree
        });
    }
}

fullTree = directionTree;

结果是一棵树只有一个根对应一个方向,其中的特征是正确的,以及特征内的分段。

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

我通过复制我所拥有的获胜公式找到了解决方案。正如问题The result is a tree with only one root that corresponds to a direction, and the characteristics in it are correct, as well as the segments inside the characteristics.

中所述

我选择了两棵树,一棵在另一棵下面,每个方向一棵。问题解决了。