如何将 XDocument 元素放入组合框(第二个框依赖于第一个框)(C# .net 3.5)
我正在尝试获取 XML 并显示两个组合框。第一个组合框将包含与provinceCode 元素不同的列表(即,没有重复项)。第二个组合框将仅显示与provinceCode匹配的nameEN元素。这是我的 XML 示例:
<siteList>
<site code="s0000001">
<nameEn>Edmonton</nameEn>
<provinceCode>AB</provinceCode>
</site>
<site code="s0000002">
<nameEn>Vancouver</nameEn>
<provinceCode>BC</provinceCode>
</site>
...
</siteList>
我的 XDocument 来源于此:
XDocument loaded = XDocument.Parse(strSiteList);
我正在努力解决如何提取唯一的省份列表的问题。它是这样的:
var list = loaded.Descendants("provinceCode").Distinct;
但我是 C# 和 XDocument 的新手,我不知道要使用什么类型的变量,所以我得到“无法将方法组分配给隐式类型的局部变量”。
我完全不知道如何处理组合框。我在 stackoverflow 和 google 上进行了快速搜索,但似乎没有任何与 C# 中的 XDocument 和依赖组合框相关的内容。使用 XDocument 是错误的方法吗?
谢谢!
I'm trying to take XML and display two comboboxes. The first combobox will contain a distinct list (i.e., no duplicates) from the provinceCode elements. The second combobox will show only nameEN elements matching the provinceCode. Here is a sample of my XML:
<siteList>
<site code="s0000001">
<nameEn>Edmonton</nameEn>
<provinceCode>AB</provinceCode>
</site>
<site code="s0000002">
<nameEn>Vancouver</nameEn>
<provinceCode>BC</provinceCode>
</site>
...
</siteList>
I have my XDocument from this:
XDocument loaded = XDocument.Parse(strSiteList);
I'm struggling with how to extract the unique list of provinces. It's something like:
var list = loaded.Descendants("provinceCode").Distinct;
but I'm new to C# and XDocument and I don't know what type of variable to use so I get "Cannot assign method group to an implicitly-typed local variable".
And I'm totally in the dark on how do to the comboboxes. I've done a quick search on stackoverflow and google, but there doesn't seem to be anything relevant on both XDocument and dependent comboboxes in C#. Is using XDocument the wrong approach?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您实际上并没有调用该方法。你可以这样写:
注意括号。
但我认为这实际上并没有达到你想要的效果。我怀疑你想要:
这会给你一个不同省份代码的列表作为字符串列表。
目前还不太清楚您对第二个列表的含义 - 这是否意味着仅匹配单个省份代码?如果是这样:
The problem is that you're not actually calling the method. You could write:
Note the brackets.
but I don't think that actually does what you want. I suspect you want:
That will give you a list of distinct province codes as a list of strings.
It's not quite clear what you mean about the second list - is that meant to match just a single province code? If so: