Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing current/selected item in ListView in WinForms

I have a ListView with about 400 entries. I need to search thru it for a value and when found I'm setting it to Selected and I would like ListView to somehow scroll to this item and show it on the screen.

How can I do this? Will setting .Focused do it?

        foreach (ListViewItem item in someListView.Items) {
            string varID = item.SubItems[0].Text;
            if (varID == someID) {
                item.Selected = true;
                item.BackColor = Color.Aquamarine;
                item.Focused = true;
                break;
            }
        }
like image 591
MadBoy Avatar asked Oct 27 '10 18:10

MadBoy


1 Answers

Try using item.EnsureVisible();

like image 107
Jeff Ogata Avatar answered Oct 31 '22 20:10

Jeff Ogata