Hi I am using the following to randomize a ListView in C#.
I am wondering if there is a more efficient way to do this as it currently takes 6 seconds per 5000 items.
Looking for working example that would be better than mine.
lvTitles.BeginUpdate();
ListView.ListViewItemCollection list = lvTitles.Items;
Random rng = new Random();
int n = list.Count;
while (n > 1)
{
n--;
int k = rng.Next(n + 1);
ListViewItem value1 = (ListViewItem)list[k];
ListViewItem value2 = (ListViewItem)list[n];
list[k] = new ListViewItem();
list[n] = new ListViewItem();
list[k] = value2;
list[n] = value1;
}
lvTitles.EndUpdate();
Aucun commentaire:
Enregistrer un commentaire