当我的数据网格视图中的下拉组合框的编辑控件浮出水面,并且用户扩展宽度时,会出现一个辅助组合框。
这似乎不是由 AutoGeneratedColumns 引起的,因为我将其设置为 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;
}
}
}
编辑:
EnableDisableCell() 方法似乎不是罪魁祸首。我将其注释掉并看到了相同的工件。