I have a custom ComboBox control that I want to use in a DataGridView. I first inherited DataGridViewCell and am trying to achieve my goals overriding the Paint() method. The problem is that after inheriting DataGridViewColum and setting the CellTemplate property to a new instance of my CustomDataGridViewCell class, the cell is grey with no contents.
I'm not really sure that this is the correct approach, so any direction is appreciated.
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
{
// Call MyBase.Paint() without passing object for formattedValue param
base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, "", errorText, cellStyle, advancedBorderStyle,
paintParts);
// Set ComboBox properties
_cBox.CheckOnClick = true;
_cBox.DrawMode = System.Windows.Forms.DrawMode.Normal;
_cBox.DropDownHeight = 1;
_cBox.IntegralHeight = false;
_cBox.Location = new System.Drawing.Point(cellBounds.X, cellBounds.Y);
_cBox.Size = new System.Drawing.Size(cellBounds.Width, cellBounds.Height);
_cBox.ValueSeparator = ", ";
_cBox.Visible = true;
_cBox.Show();
}
Oh, and the _cBox class variable references an object instantiated at variable declaration.