Ejemplo n.º 1
0
        public void AddControl(Control c, ListViewItem ownerItem, DockStyle dock)
        {
            if (c == null)
            {
                throw new ArgumentNullException("Control cannot be null!");
            }
            if (ownerItem == null)
            {
                throw new ArgumentNullException("ListViewItem cannot be null!");
            }
            if (this.Items.Count == 0)
            {
                throw new IndexOutOfRangeException("ListViewEx has no items!");
            }
            if (!this.Items.Contains(ownerItem))
            {
                throw new InvalidDataException("ListViewItem not found in the item's list!");
            }

            var nc = new InternalControl()
            {
                Control   = c,
                Column    = 1,
                DockStyle = dock,
                Item      = ownerItem,
                Row       = this.Items.IndexOf(ownerItem)
            };

            foreach (InternalControl ic in _internalControls)
            {
                if (ic.Control == c)
                {
                    throw new Exception("Control already exists!");
                }
                if (ic.Control.Name == c.Name)
                {
                    throw new Exception("Control with that name already exists!");
                }
            }

            _internalControls.Add(nc);
            this.Controls.Add(c);
        }
Ejemplo n.º 2
0
        public void AddControl(Control c, int col, int row, DockStyle dock)
        {
            if (c == null)
            {
                throw new ArgumentNullException("Control cannot be null!");
            }
            if (col >= this.Columns.Count)
            {
                throw new IndexOutOfRangeException("Column is out of range!");
            }
            if (row >= this.Items.Count)
            {
                throw new IndexOutOfRangeException("Row is out of range!");
            }

            var nc = new InternalControl()
            {
                Control   = c,
                Column    = col,
                DockStyle = dock,
                Row       = row,
                Item      = this.Items[row]
            };

            foreach (InternalControl ic in _internalControls)
            {
                if (ic.Control == c)
                {
                    throw new Exception("Control already exists!");
                }
                if (ic.Control.Name == c.Name)
                {
                    throw new Exception("Control with that name already exists!");
                }
            }

            _internalControls.Add(nc);
            this.Controls.Add(c);
        }