gpt4 book ai didi

c# - 构建 TreeView 问题

转载 作者:行者123 更新时间:2023-12-03 22:52:21 26 4
gpt4 key购买 nike

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

像这样:

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

这是我现在的重点:

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;

结果是一棵树只有一个根对应一个方向,里面的特征是正确的,特征里面的段也是正确的。

有人可以帮忙吗?

最佳答案

我通过复制我拥有的获胜公式找到了解决方案。如问题 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. 所述

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

关于c# - 构建 TreeView 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29852691/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com