我正在编写一个编程文件,其中我从XML文件中查询了所有50个美国州的名称,缩写,填充和区域。我试图将数据输出到listview控件,每个元素进入其各自的列(名称列在列名称等)。我可以通过使用"按名称递增的顺序来获取按字母顺序排列的名称"在查询中,缩写和其他信息不会与名称一致。我试图按名称订购其他数据,但根本没有做任何事情。 名称查询的示例
Dim QueryStates = From State In States.Descendants("state")
Let name = State.<name>.Value
Order By name Ascending
Select name
NameArr = QueryStates.ToArray
Dim queryStates2 = From state In States.Descendants("state")
Let abb = state.<abbreviation>.Value
Order By Name Ascending
Select abb
abbArr = queryStates2.ToArray
Dim QueryStates3 = From state In States.Descendants("state")
Let area = state.<area>.Value
Order By Name Ascending
Select area
AreaArr = QueryStates3.ToArray
Dim queryStates4 = From state In States.Descendants("state")
Let pop = state.<population>.Value
Order By Name Ascending
Select pop
PopArr = queryStates4.ToArray
这是我尝试输出数据的地方,名称按字母顺序排列就好了, 但没有其他数据。 temp是一个字符串变量,CurrentState是一个长度为3的字符串数组 itm是listview项,lstvw_Statechrt是listview控件,带有4 coloumns
For x As Integer = 0 To 49
temp = NameArr(x) & "," & abbArr(x) & "," & AreaArr(x) & "," & PopArr(x)
CurrentState = temp.Split(",")
itm = New ListViewItem(CurrentState)
lstvw_Statechrt.Items.Add(itm)
Next
所以我的问题是,有没有人有任何关于这样做的建议?
答案 0 :(得分:0)
这将是C#:
var query = States.Descendants("state")
.Select(s=> new {
name=s.<area>.Value,
pop = s.<population>.Value,
abb = s.<abbreviation>.Value,
area = s.<area>.Value
})
.OrderBy(s=>s.name);
让我们看一下在线C#到vb转换器的用途:
Dim query = States.Descendants("state").[Select](Function(s) New With { _
Key .name = s.area.Value, _
Key .pop = s.population.Value, _
Key .abb = s.abbreviation.Value, _
Key .area = s.area.Value _
}).OrderBy(Function(s) s.name)