I'm trying to fill my listview in Windows forms with some sample data. I have a List of transactions whose properties are like following:
public float NetAmount { get; set; }
public DateTime TimeStamp { get; set; }
public string TransactionID { get; set; }
This is how the so far sample data has been put to the listview like following:
private void seedListView(List<Transactions> list)
{
List<string[]> _nesto = new List<string[]>();
//Define
var data = new[]
{
new []{"Lollipop", "392", "0.2"},
new []{"KitKat", "518", "26.0"},
new []{"Ice cream sandwich", "237", "9.0"},
new []{"Jelly Bean", "375", "0.0"},
new []{"Honeycomb", "408", "3.2"}
};
//Add
foreach (string[] version in data)
{
var item = new ListViewItem(version);
materialListView1.Items.Add(item);
}
}
With the data as data source for the listview I get the following output:
Lollipop 392 0.2
KitKat 518 26.2
HoneyComb 408 3.2
Now I need to do the same, but instead of that I'd like to have the listview filled with the items from the list that I passed into the function like this:
15,2 2016-02-01 125215FESSEFOKP
19.2 2016-02-01 125215FESSEFOKP
13.6 2016-02-01 125215FESSEFOKP
15.9 2016-02-01 125215FESSEFOKP
Where 15.2 is net amount , 2016-02-01 is the timestamp and 125215FESSEFOKP is TransactionID...
How could I do this dynamically ?
Edit: I've did it like this:
List<string[][]> _nesto = new List<string[][]>();
string[][] data = null;
foreach (var item in list)
{
data = new[] { new[] { item.NetAmount.ToString(), item.TimeStamp.ToString(), item.TransactionID.ToString() } };
_nesto.Add(data);
}
ListViewItem it;
foreach (var item in _nesto)
{
foreach (string[] version in item)
{
it = new ListViewItem(version);
materialListView1.Items.Add(it);
}
}
Does anyone have a more cleaner solution than this one? This seems far too much code that I wrote for a simple thing like this :D