我有这个XML文件 我从中抓取所有数据:
<?xml version="1.0" encoding="utf-8"?>
<Tabel>
<Member>
<Naam>Cruciatum</Naam>
<Kills>10</Kills>
<Deaths>2</Deaths>
<Score>2222</Score>
</Member>
<Member>
<Naam>test</Naam>
<Kills>123</Kills>
<Deaths>12</Deaths>
<Score>12222</Score>
</Member>
<Member>
<Naam>test2</Naam>
<Kills>159</Kills>
<Deaths>12</Deaths>
<Score>2222</Score>
</Member>
<Member>
<Naam>test3</Naam>
<Kills>159</Kills>
<Deaths>122</Deaths>
<Score>222284</Score>
</Member>
<Member>
<Naam>test4</Naam>
<Kills>15</Kills>
<Deaths>1229</Deaths>
<Score>129453</Score>
</Member>
</Tabel>
我用5个不同的列表框(每个儿童节点1个在“成员”栏下)来显示。
我有这个代码 这样做的代号。
Public Class Rank
Dim memberNodes As XmlNodeList
Dim memberNode As XmlNode
Dim x As Short
Dim dataNodes As XmlNodeList
Dim firstinrow As Boolean
Dim datalist(5) As String
Dim y As Short
Private Sub Rank_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
lstView.Items.Clear()
x = 0
Dim doc As New XmlDocument()
doc.Load("C:Members.xml")
memberNodes = doc.GetElementsByTagName("Member")
For Each memberNode In memberNodes
dataNodes = memberNode.ChildNodes
y = 1
For Each dataNode As XmlNode In dataNodes
datalist(y) = dataNode.InnerText
datalist(0) = (x + 1).ToString
y += 1
Next
datalist(5) = datalist(4)
datalist(4) = FormatNumber((datalist(2) / datalist(3)), 3)
Dim lvi As New ListViewItem(datalist)
lstView.Items.Add(lvi)
x += 1
Next
End Sub
End Class
That code is working fine for now, displaying the full list. But now I need all the data sorted by the values in the Score column of the listview, so for in the following example:
我需要第一行说:"1 测试3 159 122 122 1.33 222284"
第二行,分数第二名,等等。
Update: Instead of seperate listboxes I m now using 1 listview, as recommended by @SteveDog