Exemplo n.º 1
0
        //=====================================================================

        /// <summary>
        /// This is used to clone the column
        /// </summary>
        /// <returns>A clone of the column</returns>
        public override object Clone()
        {
            UserControlComboBoxColumn clone = (UserControlComboBoxColumn)base.Clone();

            clone.DropDownControl = dropDownControl;

            return(clone);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This initializes the control used to edit the cell
        /// </summary>
        /// <param name="rowIndex">The zero-based row index of the cell's location.</param>
        /// <param name="initialFormattedValue">An object that represents the value displayed by the cell when
        /// editing is started.</param>
        /// <param name="dataGridViewCellStyle">The cell style.</param>
        public override void InitializeEditingControl(int rowIndex, object initialFormattedValue,
                                                      DataGridViewCellStyle dataGridViewCellStyle)
        {
            UserControlComboBoxColumn         owner = (UserControlComboBoxColumn)base.OwningColumn;
            UserControlComboBoxEditingControl box;
            string text;

            if (dataGridViewCellStyle == null)
            {
                throw new ArgumentNullException("dataGridViewCellStyle");
            }

            base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);

            box = base.DataGridView.EditingControl as UserControlComboBoxEditingControl;

            if (box != null)
            {
                if ((base.GetInheritedState(rowIndex) & DataGridViewElementStates.Selected) ==
                    DataGridViewElementStates.Selected)
                {
                    base.DataGridView.EditingPanel.BackColor = dataGridViewCellStyle.SelectionBackColor;
                }

                box.DropDownStyle    = ComboBoxStyle.DropDownList;
                box.MaxDropDownItems = base.MaxDropDownItems;
                box.DataSource       = null;
                box.DisplayMember    = box.ValueMember = null;
                box.Items.Clear();

                // The default selection values and drop down control type are stored at the column level
                box.DropDownControl         = owner.DropDownControl;
                box.EnforceDefaultSelection = owner.EnforceDefaultSelection;
                box.DefaultSelection        = owner.DefaultSelection;

                box.DisplayMember = base.DisplayMember;
                box.ValueMember   = base.ValueMember;
                box.DataSource    = base.DataSource;

                if (base.HasItemCollection && base.DataSource == null && base.Items.Count > 0)
                {
                    box.Items.AddRange(base.Items.InnerList.ToArray());
                }

                box.SortOrder = base.SortOrder;
                box.FlatStyle = base.FlatStyle;

                text = initialFormattedValue as string;

                if (text == null)
                {
                    text = String.Empty;
                }

                box.Text = text;

                if (box.SelectedIndex == -1 && box.Items.Count != 0)
                {
                    box.SelectedIndex = 0;
                }

                base.EditingComboBox = box;

                // If the height is greater than the standard control, erase the area below it
                if (base.OwningRow.Height > 21)
                {
                    Rectangle rc = base.DataGridView.GetCellDisplayRectangle(base.ColumnIndex, rowIndex, true);
                    rc.Y      += 21;
                    rc.Height -= 21;
                    base.DataGridView.Invalidate(rc);
                }
            }
        }