我做了相当简单的改变来解决我的问题。
我必须把坐标改成相对于窗户的坐标,而不是
DataGridView
,呼叫
Controls.Add()
对于所属窗体,并将控件重新定位到
数据表格控件
:
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)
{
  // Just paint the border (because it shows outside the ComboBox bounds)
 this.PaintBorder(graphics, clipBounds, cellBounds, cellStyle, borderStyle);
int cellX = this.DataGridView.Location.X + cellBounds.X;
int cellY = this.DataGridView.Location.Y + cellBounds.Y;
  // Create ComboBox and set properties
  this.cBox = new CheckedComboBox();
  this.cBox.DropDownHeight = 1;
  this.cBox.IntegralHeight = false;
  this.cBox.Location = new Point(cellX, cellY);
  this.cBox.Size = new Size(cellBounds.Width, cellBounds.Height);
  this.cBox.ValueSeparator = ", ";
 Â
  // Add to form and position in front of DataGridView
  this.DataGridView.FindForm.Controls.Add(this.cBox);
  this.cBox.BringToFront();
}