Exemple #1
0
 public void ScrollToItem(CustomListViewItem item)
 {
     if (_items.Count > 0)
     {
         this.ScrollControlIntoView(item);
     }
 }
Exemple #2
0
        private void AddMessage(CustomListViewItem item, bool selfSender)
        {
            CustomListViewItem lastItem = customListView1.GetLastItem();

            bool     insertDateInfo = false;
            DateTime itemDate       = (item as IChatMessageItem).Message.MessageDate;

            if (lastItem == null)
            {
                insertDateInfo = true;
            }
            else
            {
                if (itemDate.Date > (lastItem as IChatMessageItem).Message.MessageDate.Date)
                {
                    insertDateInfo = true;
                }
            }

            bool wasScrolledToBottom = customListView1.IsScrolledToBottom();

            if (insertDateInfo)
            {
                customListView1.AddItem(new ChatMessageInfoItem(new MessageItem(DateTime.UtcNow)));
            }

            customListView1.AddItem(item);

            if (_chatItem.Selected && (wasScrolledToBottom || selfSender))
            {
                customListView1.ScrollToBottom();
            }
        }
Exemple #3
0
        public void SelectItem(CustomListViewItem item)
        {
            this.SuspendLayout();

            OnSelectItem(item);

            this.ResumeLayout();
        }
Exemple #4
0
        public bool RemoveItem(CustomListViewItem item)
        {
            int index = _items.IndexOf(item);

            if (index > -1)
            {
                this.SuspendLayout();

                this.Controls.Remove(item);
                _items.Remove(item);

                item.Click       -= item_Clicked;
                item.DoubleClick -= item_DoubleClick;
                item.MouseUp     -= item_MouseUp;
                item.KeyPress    -= item_KeyPress;
                item.KeyUp       -= item_KeyUp;
                item.KeyDown     -= item_KeyDown;
                item.SortList    -= item_SortList;

                ReArrangeItems();

                if (_selectedItem == item)
                {
                    if (_items.Count > 0)
                    {
                        if (index > 0)
                        {
                            OnSelectItem(_items[index - 1]);
                        }
                        else
                        {
                            OnSelectItem(_items[index]);
                        }

                        if (ItemClick != null)
                        {
                            ItemClick(this, EventArgs.Empty);
                        }
                    }
                    else
                    {
                        _selectedItem = null;
                    }
                }

                this.ResumeLayout();

                return(true);
            }

            return(false);
        }
Exemple #5
0
        private void ReArrangeItems()
        {
            if (_items.Count > 0)
            {
                int requiredItemWidth = this.Width - _borderPadding * 2 - this.Padding.Left - this.Padding.Right;

                if (base.VerticalScroll.Visible)
                {
                    requiredItemWidth -= 17;
                }

                bool doneOnce = false;

                while (true)
                {
                    //check width
                    if (requiredItemWidth != _items[0].Width)
                    {
                        for (int i = 0; i < _items.Count; i++)
                        {
                            _items[i].Width = requiredItemWidth;
                        }
                    }

                    //check item placement
                    _items[0].Location = new Point(this.Padding.Left, this.Padding.Top + this.AutoScrollPosition.Y);

                    for (int i = 1; i < _items.Count; i++)
                    {
                        CustomListViewItem previousControl = _items[i - 1];
                        CustomListViewItem currentControl  = _items[i];

                        currentControl.Location = new Point(previousControl.Location.X, previousControl.Location.Y + previousControl.Height + this.Padding.Bottom);
                    }

                    CustomListViewItem lastItem = _items[_items.Count - 1];

                    if (!doneOnce && !base.VerticalScroll.Visible && ((lastItem.Top + lastItem.Height) > this.Height))
                    {
                        requiredItemWidth -= 17;
                        doneOnce           = true;
                        continue;
                    }

                    break;
                }
            }
        }
Exemple #6
0
        private bool OnSelectItem(CustomListViewItem item)
        {
            if (_selectedItem != item)
            {
                _selectedItem = item;

                foreach (CustomListViewItem control in _items)
                {
                    control.Selected = control.Equals(item);
                }

                return(true);
            }

            return(false);
        }
Exemple #7
0
        public CustomListViewItem AddItem(CustomListViewItem item)
        {
            this.SuspendLayout();

            item.SeparatorColor = this.SeparatorColor;

            item.Click       += item_Clicked;
            item.DoubleClick += item_DoubleClick;
            item.MouseUp     += item_MouseUp;
            item.KeyPress    += item_KeyPress;
            item.KeyUp       += item_KeyUp;
            item.KeyDown     += item_KeyDown;
            item.SortList    += item_SortList;

            if (_items.Count > 0)
            {
                item.Width = _items[_items.Count - 1].Width;
            }

            _items.Add(item);
            this.Controls.Add(item);

            if (_sortItems)
            {
                _items.Sort(delegate(CustomListViewItem item1, CustomListViewItem item2) { return(string.Compare(item1.ToString(), item2.ToString())); });
            }

            ReArrangeItems();

            this.ResumeLayout();

            if (_selectedItem == null)
            {
                _selectedItem = item;
                item.Selected = true;
            }

            if (_autoScrollToBottom)
            {
                this.ScrollControlIntoView(item);
            }

            return(item);
        }
Exemple #8
0
        public void TrimListFromTop(int totalItemsToKeep)
        {
            if (_items.Count > totalItemsToKeep)
            {
                int totalItemsToRemove = _items.Count - totalItemsToKeep;
                List <CustomListViewItem> itemsToRemove = new List <CustomListViewItem>(totalItemsToRemove);

                for (int i = 0; i < totalItemsToRemove; i++)
                {
                    if (!_items[i].AllowTriming())
                    {
                        break;
                    }

                    itemsToRemove.Add(_items[i]);
                }

                this.SuspendLayout();

                foreach (CustomListViewItem item in itemsToRemove)
                {
                    this.Controls.Remove(item);
                    _items.Remove(item);

                    item.Click       -= item_Clicked;
                    item.DoubleClick -= item_DoubleClick;
                    item.MouseUp     -= item_MouseUp;
                    item.KeyPress    -= item_KeyPress;
                    item.KeyUp       -= item_KeyUp;
                    item.KeyDown     -= item_KeyDown;
                    item.SortList    -= item_SortList;

                    if (_selectedItem == item)
                    {
                        _selectedItem = null;
                    }
                }

                ReArrangeItems();

                this.ResumeLayout();
            }
        }
Exemple #9
0
        private void item_MouseUp(object sender, MouseEventArgs e)
        {
            CustomListViewItem obj = sender as CustomListViewItem;

            this.SuspendLayout();

            bool selected = OnSelectItem(obj);

            this.ResumeLayout();

            if (selected && (ItemClick != null))
            {
                ItemClick(sender, EventArgs.Empty);
            }

            if (ItemMouseUp != null)
            {
                ItemMouseUp(sender, e);
            }
        }
Exemple #10
0
        public void InsertItemsAtTop(IEnumerable <CustomListViewItem> items)
        {
            this.SuspendLayout();

            this.Controls.Clear();

            foreach (CustomListViewItem item in items)
            {
                item.SeparatorColor = this.SeparatorColor;

                item.Click       += item_Clicked;
                item.DoubleClick += item_DoubleClick;
                item.MouseUp     += item_MouseUp;
                item.KeyPress    += item_KeyPress;
                item.KeyUp       += item_KeyUp;
                item.KeyDown     += item_KeyDown;
                item.SortList    += item_SortList;
            }

            CustomListViewItem previousTopItem = null;

            if (_items.Count > 0)
            {
                previousTopItem = _items[0];
            }

            _items.InsertRange(0, items);
            this.Controls.AddRange(_items.ToArray());

            ReArrangeItems();

            if (previousTopItem != null)
            {
                this.ScrollControlIntoView(previousTopItem);
            }

            this.ResumeLayout();
        }
 public bool RemoveItem(CustomListViewItem item)
 {
     return(customListView1.RemoveItem(item));
 }
 public CustomListViewItem AddItem(CustomListViewItem item)
 {
     return(customListView1.AddItem(item));
 }