J'ai un contrôle personnalisé ComboBox
que je veux utiliser dans un DataGridViewCell
. J'ai d'abord hérité DataGridViewCell
et j'essaie de remplacer la méthode Paint()
pour peindre le ComboBox
dans la cellule.Comment puis-je dessiner un ComboBox personnalisé dans un DataGridViewCell?
Mon problème est que, après avoir hérité DataGridViewColumn
et définir la propriété CellTemplate
à une nouvelle instance de ma classe CustomDataGridViewCell
, la cellule est gris sans contenu.
La variable de classe cBox
est instanciée dans l'objet 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();
}
Comment puis-je peindre correctement le ComboBox
dans la cellule?
vous fournir le Hi.Could fichiers à avoir un CheckedCombBox dans DataGridView? – San