Buonasera!
Con il seguente codice riesco a popolare una listbox da un file XML.
Per favore vorrei sapere se è possibile “semplificare” il codice sotto, ho provato con un ciclo for next ma riesco ad ottenere solamente una riga:
Var lb As Listbox = XMLList
Var mKey As String = "//ElencoPrezzi"
Var nodes As XmlNodeList = xml.XQL(mKey)
Var node As XmlNode
For n As Integer = 0 To nodes.Length - 1
node = nodes.Item(n) //Numero nodi
//Layout Listbox
lb.HasHeading = True
lb.ColumnCount = node.ChildCount
For x As Integer = 0 To lb.ColumnCount -1
lb.Heading(x) = node.Child(n).Name
n = n + 1
Next
Next
For i As Integer = 0 To nodes.Length - 1
node = nodes.Item(i) //Numero nodi
// Add rows
lb.AddRow("")
If node.Child(0).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 0) = node.Child(0).FirstChild.Value
If node.Child(1).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 1) = node.Child(1).FirstChild.Value
If node.Child(2).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 2) = node.Child(2).FirstChild.Value
If node.Child(3).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 3) = node.Child(3).FirstChild.Value
If node.Child(4).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 4) = node.Child(4).FirstChild.Value
If node.Child(5).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 5) = node.Child(5).FirstChild.Value
If node.Child(6).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 6) = node.Child(6).FirstChild.Value
If node.Child(7).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 7) = node.Child(7).FirstChild.Value
If node.Child(8).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 8) = node.Child(8).FirstChild.Value
If node.Child(9).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 9) = node.Child(9).FirstChild.Value
If node.Child(10).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 10) = node.Child(10).FirstChild.Value
If node.Child(11).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 11) = node.Child(11).FirstChild.Value
If node.Child(12).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 12) = node.Child(12).FirstChild.Value
If node.Child(13).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 13) = node.Child(13).FirstChild.Value
If node.Child(14).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 14) = node.Child(14).FirstChild.Value
If node.Child(15).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 15) = node.Child(15).FirstChild.Value
If node.Child(16).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 16) = node.Child(16).FirstChild.Value
If node.Child(17).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 17) = node.Child(17).FirstChild.Value
If node.Child(18).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 18) = node.Child(18).FirstChild.Value
If node.Child(19).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 19) = node.Child(19).FirstChild.Value
If node.Child(20).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 20) = node.Child(20).FirstChild.Value
If node.Child(21).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, 21) = node.Child(21).FirstChild.Value
//Provo a scrivere il codice sotto escludendo le righe sopra ma popola solo una riga
For y As Integer = 0 To lb.ColumnCount -1
If node.Child(i).FirstChild <> Nil Then lb.CellValueAt(lb.LastRowIndex, y) = node.Child(i).FirstChild.Value
i = i + 1
Next
Next
Grazie!