Beispiel #1
0
        // Setting the virtual list size this way eliminates flickering (when invalidate = false)
        // and prevents the control from scrolling to the right.
        // This idea came from http://www.dotnetmonster.com/Uwe/Forum.aspx/winform-controls/5181/Ugly-flicker-when-updating-a-ListView-in-VirtualMode
        public void SetVirtualListSize(int count, bool invalidate)
        {
            if (listViewVirtualListSizeField == null)
            {
                VirtualListSize = count;
            }
            else
            {
                try
                {
                    ListViewSetItemCountFlags flags = ListViewSetItemCountFlags.LVSICF_NOSCROLL;

                    if (!invalidate)
                    {
                        flags |= ListViewSetItemCountFlags.LVSICF_NOINVALIDATEALL;
                    }

                    SendMessage(Handle, ListViewMessages.LVM_SETITEMCOUNT, count, flags);

                    // The public ListView.VirtualListSize property drives a private member
                    // named virtualListSize that is used in the implementation of
                    // ListViewItemCollection (returned by ListView.Items) to validate
                    // indices. If this is not updated, spurious ArgumentOutOfRangeExceptions
                    // may be raised by functions and properties using the indexing
                    // operator on ListView.Items, for instance FocusedItem.
                    listViewVirtualListSizeField.SetValue(this, count);
                }
                catch
                {
                    VirtualListSize = count;
                }
            }
        }
Beispiel #2
0
 private static extern IntPtr SendMessage(IntPtr hWnd, ListViewMessages msg, int wParam, ListViewSetItemCountFlags lParam);