How do I get the start index and number of visible items in a ListView?

前端 未结 7 1981
迷失自我
迷失自我 2020-12-21 02:37

I have a listview working in virtual mode, in the LargeIcons view. Retrieves are expensive, so I want to ask for the data for all the visible items. How do I get the start

7条回答
  •  忘掉有多难
    2020-12-21 03:25

    Just off the top of my head, and I haven't tested this but could you do:

    private void GetIndexes(ListView vv, out int startidx, out int count)
    {
                ListViewItem lvi1 = vv.GetItemAt(vv.ClientRectangle.X+6, vv.ClientRectangle.Y + 6); 
                ListViewItem lvi2 = vv.GetItemAt(vv.ClientRectangle.X+6, vv.ClientRectangle.Bottom-10); 
                startidx = vv.Items.IndexOf(lvi1); 
                int endidx = vv.Items.IndexOf(lvi2);
                if (endidx == -1) endidx = vv.Items.Count;
                count = endidx - startidx;
    }
    

提交回复
热议问题