Exemplo n.º 1
0
        /// <summary>
        ///     Creates an identical copy of the current <see cref="VisualListViewItem" /> that is not attached to any list
        ///     view control.
        /// </summary>
        /// <returns>The <see cref="Object" />.</returns>
        public virtual object Clone()
        {
            VisualListViewSubItemCollection _clonedSubItemCollection = new VisualListViewSubItemCollection();

            for (var i = 0; i < _subItemCollection.Count; i++)
            {
                VisualListViewSubItem _subItem = _subItemCollection[i];

                _clonedSubItemCollection.Add(new VisualListViewSubItem(null, _subItem.Text, _subItem.ForeColor, _subItem.BackColor, _subItem.Font)
                {
                    Tag = _subItem.Tag
                });
            }

            Type _clonedType = GetType();
            VisualListViewItem _listViewItem;

            if (_clonedType == typeof(VisualListViewItem))
            {
                _listViewItem = new VisualListViewItem(_clonedSubItemCollection, _subItemCollection[0].ImageIndex);
            }
            else
            {
                _listViewItem = (VisualListViewItem)Activator.CreateInstance(_clonedType);
            }

            _listViewItem = new VisualListViewItem(_clonedSubItemCollection, -1)
            {
                ImageIndex = _subItemCollection[0].ImageIndex,
                Tag        = _tag,
                BackColor  = _backColor,
                ForeColor  = _foreColor,
                Font       = _font,
                Text       = Text
            };

            // if (!string.IsNullOrEmpty(_imageKey))
            // {
            // _listViewItem.ImageIndexer.Key = _imageKey;
            // }
            return(_listViewItem);
        }
        /// <summary>
        ///     Creates an identical copy of the current <see cref="VisualListViewItem" /> that is not attached to any list
        ///     view control.
        /// </summary>
        /// <returns>The <see cref="Object" />.</returns>
        public virtual object Clone()
        {
            VisualListViewSubItemCollection _clonedSubItemCollection = new VisualListViewSubItemCollection();

            for (var i = 0; i < _subItemCollection.Count; i++)
            {
                VisualListViewSubItem _subItem = _subItemCollection[i];

                _clonedSubItemCollection.Add(new VisualListViewSubItem(null, _subItem.Text, _subItem.ForeColor, _subItem.BackColor, _subItem.Font)
                {
                    Tag = _subItem.Tag
                });
            }

            Type _clonedType = GetType();
            VisualListViewItem _listViewItem;

            if (_clonedType == typeof(VisualListViewItem))
            {
                _listViewItem = new VisualListViewItem(_clonedSubItemCollection, _subItemCollection[0].ImageIndex);
            }
            else
            {
                _listViewItem = (VisualListViewItem)Activator.CreateInstance(_clonedType);
            }

            _listViewItem.SubItems.Clear();
            foreach (VisualListViewSubItem subItem in _clonedSubItemCollection)
            {
                _listViewItem.SubItems.Add(subItem);
            }

            _listViewItem.Checked    = _subItemCollection[0].Checked;
            _listViewItem.ImageIndex = _subItemCollection[0].ImageIndex;
            _listViewItem.Tag        = _tag;
            _listViewItem.BackColor  = _backColor;
            _listViewItem.ForeColor  = _foreColor;
            _listViewItem.Font       = _font;
            _listViewItem.Text       = Text;
            return(_listViewItem);
        }