//===================================================================== /// <summary> /// This is used to clone the column. /// </summary> /// <returns>A clone of the column</returns> public override object Clone() { MultiColumnComboBoxColumn clone = (MultiColumnComboBoxColumn)base.Clone(); clone.ColumnHeadersVisible = this.ColumnHeadersVisible; clone.RowHeadersVisible = this.RowHeadersVisible; clone.DefaultNullText = this.DefaultNullText; if (this.ColumnFilter.Count != 0) { clone.ColumnFilter.AddRange(this.ColumnFilter); } return(clone); }
/// <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) { MultiColumnComboBoxColumn owner = (MultiColumnComboBoxColumn)base.OwningColumn; MultiColumnComboBoxEditingControl box; string text; if (dataGridViewCellStyle == null) { throw new ArgumentNullException("dataGridViewCellStyle"); } base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle); box = base.DataGridView.EditingControl as MultiColumnComboBoxEditingControl; 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.DropDownWidth = dropDownWidth; box.DataSource = null; box.DisplayMember = box.ValueMember = null; box.ColumnFilter.Clear(); box.Items.Clear(); // The default selection, format, and column filter values are stored at the column level box.EnforceDefaultSelection = owner.EnforceDefaultSelection; box.DefaultSelection = owner.DefaultSelection; box.DropDownFormat.ColumnHeadersVisible = owner.ColumnHeadersVisible; box.DropDownFormat.RowHeadersVisible = owner.RowHeadersVisible; box.DropDownFormat.DefaultNullText = owner.DefaultNullText; StringCollection columnFilter = owner.ColumnFilter; if (columnFilter.Count != 0) { box.ColumnFilter.AddRange(columnFilter); } 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); } } }