我有一个ComboBox
要在DataGridViewCell
. 我首先继承DataGridViewCell
并试图覆盖在单元格Paint()
中绘制的方法ComboBox
。
我的问题是,在继承DataGridViewColumn
并将CellTemplate
属性设置为我的类的新实例后CustomDataGridViewCell
,单元格是灰色的,没有内容。
类cBox
变量在对象 ctor 中实例化。
protected override void Paint(Graphics graphics, Rectangle clipBounds,
Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState,
object value, object formattedValue, string errorText,
DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle borderStyle,
DataGridViewPaintParts paintParts)
{
// Call MyBase.Paint() without passing object for formattedValue param
base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value,
"", errorText, cellStyle, borderStyle, paintParts);
// Set ComboBox properties
this.cBox.CheckOnClick = true;
this.cBox.DrawMode = System.Windows.Forms.DrawMode.Normal;
this.cBox.DropDownHeight = 1;
this.cBox.IntegralHeight = false;
this.cBox.Location = new System.Drawing.Point(cellBounds.X, cellBounds.Y);
this.cBox.Size = new System.Drawing.Size(cellBounds.Width, cellBounds.Height);
this.cBox.ValueSeparator = ", ";
this.cBox.Visible = true;
this.cBox.Show();
}
如何正确绘制ComboBox
单元格中的内容?