例如ListView添加了一万条数据,在不拖动滚动条的情况下,可显示20条数据.在随便拉动滚动条的情况下,如何得到这20条显示出来的ListViewItem呢??

解决方案 »

  1.   

    GetItemAt method
    这个方法,通过定位坐标来取得item,然后头尾两个item之间的items就是你想要的了。GetItemAt  Retrieves the item at the specified location. 
    自己上MSDN上查,这个是LISTVIEW的方法。
      

  2.   

    3楼说的跟我现在做法一样,但总感觉别扭,呵呵~~在不同显示像素的情况下不知道会不会有影响~~,想看看有没其它方法!!
    下面是我用GetItemAt做的一个方法.#region " 获取可见行数据集 "
            public List<ListViewItem> GetShowListViewItems()
            {
                List<ListViewItem> result = new List<ListViewItem>();
                ListViewItem lvi = null;
                int defaultY = 30;//初始Y坐标,
                do
                {
                    lvi = base.GetItemAt(10, defaultY);
                    if (null != lvi)
                    {
                        defaultY += lvi.Bounds.Height;
                        result.Add(lvi);
                    }
                } while (null != lvi);
                return result;
            }
    #endregion
      

  3.   

    方法2public List<ListViewItem> GetShowListViewItems()
            {
                List<ListViewItem> result = new List<ListViewItem>();
                ListViewItem lvi = base.TopItem;
               do
                {
                    if (null != lvi)
                    {
                        result.Add(lvi);
                        if (lvi.Index + 1 < base.Items.Count)
                        {
                            lvi = base.Items[lvi.Index + 1];
                        }
                        else
                        {
                            lvi = null;
                        }
                    }
                } while (null != lvi && lvi.Bounds.Bottom < this.Height);
                return result;
            }