1

ComboBoxで使用したいカスタムコントロールがありDataGridViewCellます。私は最初に継承し、セルにペイントするメソッドをDataGridViewCellオーバーライドしようとしています。Paint()ComboBox

私の問題は、プロパティを継承してクラスの新しいインスタンスにDataGridViewColumn設定した後、セルが灰色で内容がないことです。CellTemplateCustomDataGridViewCell

クラス変数は、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セル内を正しくペイントするにはどうすればよいですか?

4

1 に答える 1