Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I draw a custom ComboBox inside a DataGridViewCell?
    primarykey
    data
    text
    <p>I have a custom <code>ComboBox</code> control that I want to use in a <code>DataGridViewCell</code>. I first inherited <code>DataGridViewCell</code> and am trying to override the <code>Paint()</code> method to paint the <code>ComboBox</code> in the cell.</p> <p>My problem is that after inheriting <code>DataGridViewColumn</code> and setting the <code>CellTemplate</code> property to a new instance of my <code>CustomDataGridViewCell</code> class, the cell is grey with no contents. </p> <p>The <code>cBox</code> class variable is instantiated in the object ctor.</p> <pre><code>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(); } </code></pre> <p>How can I correctly paint the <code>ComboBox</code> in the cell?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload