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

前端 未结 7 1957
迷失自我
迷失自我 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:33

    You could iterate through subsequent items, checking their visibility until you reach the one that isn't visible. This would give you a count of the visible items.

    For example, something like:

            for (int index = 0; index < list.Items.Count; index++)
            {
                if (list.ClientRectangle.IntersectsWith(item.GetBounds(ItemBoundsPortion.Entire)))
                {
                    // Add to the list to get data.
                }
                else
                {
                    // We got them all.
                    break;
                }
            }
    

    I'm not sure what effect sorting would have on this though.

提交回复
热议问题