Exemplo n.º 1
0
 public void ScrollToBottom()
 {
     if (_items.Count > 0)
     {
         _lastScrolledItem = _items[_items.Count - 1];
         this.ScrollControlIntoView(_lastScrolledItem);
     }
 }
Exemplo n.º 2
0
        public void SelectItem(CustomListViewItem item)
        {
            this.SuspendLayout();

            OnSelectItem(item);

            this.ResumeLayout();
        }
Exemplo n.º 3
0
        public bool RemoveItem(CustomListViewItem item)
        {
            int index = _items.IndexOf(item);

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

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

                ReArrangeItems();

                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)
                {
                    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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        private void ReArrangeItems()
        {
            if (_items.Count > 0)
            {
                //find total height of items including padding
                int totalHeightOfItems = 0;

                foreach (CustomListViewItem control in _items)
                {
                    totalHeightOfItems += control.Height + (_borderPadding * 2);
                }

                int requiredItemWidth;

                if (totalHeightOfItems > this.Height)
                {
                    //this means scrolling is enabled
                    requiredItemWidth = this.Width - _borderPadding * 2 - this.Padding.Left - this.Padding.Right - 17;
                }
                else
                {
                    //this means scrolling is disabled
                    requiredItemWidth = this.Width - _borderPadding * 2 - this.Padding.Left - this.Padding.Right;
                }

                //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);
                }
            }
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        private void AddMessage(CustomListViewItem item)
        {
            CustomListViewItem lastItem = customListView1.GetLastItem();

            bool showDate = false;

            if (lastItem == null)
            {
                showDate = true;
            }
            else
            {
                if (lastItem.GetType().Equals(typeof(ChatMessageItem)))
                {
                    if (DateTime.Now.Date > (lastItem as ChatMessageItem).MessageDate.Date)
                    {
                        showDate = true;
                    }
                }
                else if (lastItem.GetType().Equals(typeof(ChatMessageInfoItem)))
                {
                    ChatMessageInfoItem xItem = lastItem as ChatMessageInfoItem;

                    if (xItem.IsDateSet() && (DateTime.Now.Date > xItem.MessageDate.Date))
                    {
                        showDate = true;
                    }
                }
            }

            if (showDate)
            {
                customListView1.AddItem(new ChatMessageInfoItem(DateTime.Now.ToString("dddd, MMMM d, yyyy")));
            }

            customListView1.AddItem(item);

            if (_chatItem.Selected)
            {
                customListView1.ScrollToBottom();
            }
        }
Exemplo n.º 8
0
        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(this, EventArgs.Empty);
            }

            e = new MouseEventArgs(e.Button, e.Clicks, obj.Location.X + e.X, obj.Location.Y + e.Y, e.Delta);

            if (ItemMouseUp != null)
            {
                ItemMouseUp(this, e);
            }
        }
Exemplo n.º 9
0
 public CustomListViewItem AddItem(CustomListViewItem item)
 {
     return customListView1.AddItem(item);
 }
Exemplo n.º 10
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;
        }
Exemplo n.º 11
0
        public void SelectItem(CustomListViewItem item)
        {
            this.SuspendLayout();

            OnSelectItem(item);

            this.ResumeLayout();
        }
Exemplo n.º 12
0
 public void ScrollToBottom()
 {
     if (_items.Count > 0)
     {
         _lastScrolledItem = _items[_items.Count - 1];
         this.ScrollControlIntoView(_lastScrolledItem);
     }
 }
Exemplo n.º 13
0
        public bool RemoveItem(CustomListViewItem item)
        {
            int index = _items.IndexOf(item);
            if (index > -1)
            {
                this.SuspendLayout();

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

                ReArrangeItems();

                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)
                {
                    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;
        }
Exemplo n.º 14
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;
        }
Exemplo n.º 15
0
 public CustomListViewItem AddItem(CustomListViewItem item)
 {
     return(customListView1.AddItem(item));
 }
Exemplo n.º 16
0
 public bool RemoveItem(CustomListViewItem item)
 {
     return(customListView1.RemoveItem(item));
 }
Exemplo n.º 17
0
 public bool RemoveItem(CustomListViewItem item)
 {
     return customListView1.RemoveItem(item);
 }