I have hosted a custom control in datagridview, let's me say CustomControl (third party control), and cell is painting only when entering in edit mode. If exit edit mode, it is not visible so I have overrided the paint method (see below). It is working ok in windows 7 but not in windows xp. DrawToBitmap is failing. Any ideas?
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 the base class method to paint the default cell appearance.
base.Paint(
graphics,
clipBounds,
cellBounds,
rowIndex,
cellState,
value,
formattedValue,
errorText,
cellStyle,
advancedBorderStyle,
paintParts);
CustomControl customControl= (CustomControl)this.DataGridView.Rows[rowIndex].Cells[this.ColumnIndex].Value;
Bitmap img = new Bitmap(cellBounds.Width, cellBounds.Height);
// Resize propertyEditor control to cell bounds
propertyEditor.Height = cellBounds.Height;
propertyEditor.Width = cellBounds.Width;
// Sets the cell's backcolor according to the data grid view's color
customControl.BackColor = this.DataGridView.Rows[rowIndex].Cells[this.ColumnIndex].Style.BackColor;
// Finally paint the propertyEditor control
customControl.DrawToBitmap(img, new Rectangle(0, 0, customControl.Width, customControl.Height));
graphics.DrawImage(img, cellBounds.Location);
}