Reputation: 4088
So I've been playing around with the ListView
in virtualmode, but I can't seem to add items dynamically. I want to load items from a List
and display them in my ListView
. Here is the code I have so far.
private void listviewGames_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
{
if (listGames[1].Count < 1) return;
for (int index = 0; index < listGames[1].Count; index++)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = listGames[1][index];
e.Item = lvi;
}
}
Sadly, this code doesn't seem to work, it only adds the last item in the List
, why is this?
Thanks in advance,
Sapphire ~
Upvotes: 2
Views: 268
Reputation: 4542
Please try this:
private void listviewGames_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
{
if (listGames[1].Count < 1) return;
ListViewItem lvi = new ListViewItem();
lvi.Text = listGames[1][e.ItemIndex];
e.Item = lvi;
}
Upvotes: 1