I have this data coming from a XML:
var searched = from c in xml.Descendants("tbody").Descendants("tr")
let team = c.Element("td").ElementsAfterSelf("td")
select new Time
{
a = c.Element("td").ElementsAfterSelf("td").First().Value,
b = Int32.Parse(c.Descendants("td").ElementAt(3).Value),
c = Int32.Parse(c.Descendants("td").ElementAt(4).Value),
d = Int32.Parse(c.Descendants("td").ElementAt(5).Value),
e = Int32.Parse(c.Descendants("td").ElementAt(6).Value),
f = Int32.Parse(c.Descendants("td").ElementAt(7).Value),
g = Int32.Parse(c.Descendants("td").ElementAt(8).Value),
h = Int32.Parse(c.Descendants("td").ElementAt(9).Value),
i = Int32.Parse(c.Descendants("td").ElementAt(10).Value),
j = float.Parse(c.Descendants("td").ElementAt(11).Value)
};
Done this, I’m displaying them in a ListBox:
foreach (var item in searched)
{
listBox1.Items.Add(item.a + " " + item.b + " " + item.c + " " +
item.d + " " + item.e + " " + item.f + " " + item.g + " " +
item.h + " " + item.i + " " + item.j);
listBox1.Items.Add(" ");
}
It prints fine, that’s how I wanted it.
Now I need to format it.
Now, it is printing like this:
a b c d e f g h j
However, the variable’s content differs in size. So the information do not get very organized.
So I wanted something like:
a|b|c|d|e|f|g|h|j
a|b|c|d|e|f|g|h|j
In which the | represents a column. I was thinking about a grid inside a list box but then I got lost on how to do it.
Well, what about a ListBox with an
ItemTemplatetailored to your data?This is the
ListBox:It uses a grid for each item, putting the values in separate columns. You can experiment with the column sizes.
This demonstrates the binding:
I just create a list with made-up data and set it as
ItemsSourceof the list box. In your case the data will come from the XML.And I used this mock class for testing:
It only has 3 fields for demonstrating how it works. You can easily add the other fields as well. For each additional field add one additional
ColumnDefinitionandTextBlockin the XAML and set theBindingaccordingly.