开发者

Showing current/selected item in ListView in WinForms

开发者 https://www.devze.com 2023-01-22 20:03 出处:网络
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 sc

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;
            }
        }


Try using item.EnsureVisible();

0

精彩评论

暂无评论...
验证码 换一张
取 消