I want to write an application that will display data from a CSV file.
I thought it would be easiest to use a listbox to do this.
I’m just not sure how to define the data template in order to accommodate as many columns as the csv wishes to define. Is there a way to define the number of columns in, say, a grid based on maybe the item count in a list?
Use a ListView rather than a ListBox, then you can use a GridView for the columns, or you could use a DataGrid which additionally can create columns automatically based on the data it gets, this requires properties though, which are not as nice to create on the fly.
I would suggest you parse the data into array objects and you create the columns by iterating over its length. Adding bindings like this:
new Binding("[" + i + "]").Here’s a rough outline: