// ======================================================================== // Methods #region === Methods /// <returns> /// An <see cref="T:System.Object"/> that represents the cloned <see cref="T:System.Windows.Forms.DataGridViewBand"/>. /// </returns> public override object Clone() { DataGridViewImageComboBoxColumn clone = base.Clone() as DataGridViewImageComboBoxColumn; if (clone != null) { clone.ImageList = ImageList; clone.ImageSize = ImageSize; clone.Items = new List <ImageComboBoxItem>(Items); } return(clone); }
/// <summary> /// Attaches and initializes the hosted editing control. /// </summary> /// <param name = "rowIndex">The index of the cell's parent row.</param> /// <param name = "initialFormattedValue">The initial value to be displayed in the control.</param> /// <param name = "dataGridViewCellStyle">A <see cref = "T:System.Windows.Forms.DataGridViewCellStyle" /> that determines the appearance of the hosted control.</param> public override void InitializeEditingControl(int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle) { base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle); DataGridViewImageComboBoxEditingControl control = DataGridView.EditingControl as DataGridViewImageComboBoxEditingControl; DataGridViewImageComboBoxColumn column = OwningColumn as DataGridViewImageComboBoxColumn; if (control != null && column != null) { control.ImageList = column.ImageList; control.ImageSize = column.ImageSize; control.ItemHeight = column.ImageSize.Height + 2; control.Items.Clear(); control.Items.AddRange(column.Items.ToArray()); control.SelectedItem = Value as ImageComboBoxItem; } }
/// <summary> /// Paints the current <see cref = "DataGridViewImageComboBoxColumnCell" />. /// </summary> /// <param name = "graphics">The <see cref = "T:System.Drawing.Graphics" /> used to paint the cell.</param> /// <param name = "clipBounds">A <see cref = "T:System.Drawing.Rectangle" /> that represents the area of the <see cref = "T:System.Windows.Forms.DataGridView" /> that needs to be repainted.</param> /// <param name = "cellBounds">A <see cref = "T:System.Drawing.Rectangle" /> that contains the bounds of the cell that is being painted.</param> /// <param name = "rowIndex">The row index of the cell that is being painted.</param> /// <param name = "elementState">A bitwise combination of <see cref = "T:System.Windows.Forms.DataGridViewElementStates" /> values that specifies the state of the cell.</param> /// <param name = "value">The data of the cell that is being painted.</param> /// <param name = "formattedValue">The formatted data of the cell that is being painted.</param> /// <param name = "errorText">An error message that is associated with the cell.</param> /// <param name = "cellStyle">A <see cref = "T:System.Windows.Forms.DataGridViewCellStyle" /> that contains formatting and style information about the cell.</param> /// <param name = "advancedBorderStyle">A <see cref = "T:System.Windows.Forms.DataGridViewAdvancedBorderStyle" /> that contains border styles for the cell that is being painted.</param> /// <param name = "paintParts">A bitwise combination of the <see cref = "T:System.Windows.Forms.DataGridViewPaintParts" /> values that specifies which parts of the cell need to be painted.</param> protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { //Call the base to draw the combo box itself. base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, null, errorText, cellStyle, advancedBorderStyle, paintParts); //Now we will draw the current content of the box. DataGridViewImageComboBoxColumn column = ((DataGridViewImageComboBoxColumn)OwningColumn); if ((paintParts & DataGridViewPaintParts.Background) != 0 || (paintParts & DataGridViewPaintParts.All) != 0) { Rectangle rect = new Rectangle(cellBounds.X + 4, cellBounds.Y, cellBounds.Width - 4, cellBounds.Height - 1); ControlDrawHelper.DrawImageComboBoxItem(graphics, value, column.ImageList, column.ImageSize, rect, cellStyle.Font, cellStyle.ForeColor); } }