When the editing control for a drop down combo box in my datagrid view is surfaced, and the user expands the width, a secondary combo box appears.
This doesn't appear to be caused by AutoGeneratedColumns since I have that set to false.
protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e)
{
base.OnCellPainting(e);
if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
{
DataGridViewRow currentRow = this.Rows[e.RowIndex];
DataGridViewCell currentCell = currentRow.Cells[e.ColumnIndex];
DataItem item = currentRow.DataBoundItem as DataItem;
if (item != null)
{
if (new string[] { "Property1", "Property2" }.Contains(this.Columns[e.ColumnIndex].DataPropertyName))
{
EnableDisableCell(currentCell, item);
}
}
}
}
private void EnableDisableCell(DataGridViewCell cell, DataItem boundItem)
{
if (cell != null)
{
switch (cell.OwningColumn.DataPropertyName)
{
case "Property1":
if (boundItem.AllowP1Assignment)
{
cell.Enable();
}
else
{
cell.Disable();
}
break;
case "Property2":
if (boundItem.AllowP2Assignment)
{
cell.Enable();
}
else
{
cell.Disable();
}
break;
default:
break;
}
}
}
EDIT:
The EnableDisableCell() method doesn't seem to be the culprit. I commented it out and saw the same artifacts.