I populate my System.Windows.Forms.ListView with results from my database as such:
foreach (DataRow row in theTable.Rows) { ...build item from row.. myListView.Items.Add(item); }
And then I want to sort my list in a different order than the rows returned from the DB, so I call
myListView.Sort();
But then, when I want to select the top item in the list, it will not work, it selected something different from the top item:
myListView.Items[0].Selected = true;
It makes sense because the Items collection is added in the order of the rows from the table that iterates through the foreach loop.
Using myListView.TopItem.Seleted = true does not work either.
So, how do I select the topmost item in the list? AFTER I sorted it?
Thanks for any answers.
source share