0

내 DataGrid보기에서 드롭 다운 콤보 상자의 편집 컨트롤이 떠오르고 사용자가 너비를 확장하면 보조 콤보 상자가 나타납니다.DataGridView : 신비한 두 번째 드롭 다운

enter image description here

이것은 내가 false로 그 설정이 있기 때문에 AutoGeneratedColumns에 의해 발생하는 경우가 없습니다.

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() 메소드는 범인 될 것 같지 않습니다. 나는 그것을 주석 처리했고 동일한 유물을 보았다.

+1

은 그냥 페인트 오류입니까? 아니면 둘 다 작동합니까? – TaW

+0

@Taw : 드롭 다운이 항상 왼쪽 수직 열의 행에 대해 (항상 오른쪽 콤보 상자로 플러시되지 않으므로) 페인트 오류로 나타납니다. 또한 OnPaint 호출에는 항상 this.GetHashCode() 값이 동일합니다. 또한 너비는 OnPaint 호출마다 다릅니다. – micahhoover

+1

아마 DGV 또는 셀 영역을 무효화하면 사라질 것입니다 ..? Paint 이벤트에서 셀의 활성화 된 상태를 변경하면 확실하게 의심 스럽습니다. 이것은 어떤 그림보다 먼저 일어 났어야했다. – TaW

답변

1

많은 TAW 덕분에이 웹 사이트 :

http://www.csharp-examples.net/redraw-control-on-resize/

난 그냥 생성자에이를 추가 할 필요

:

ResizeRedraw = true; 

분명히 당신은 또한 관련 행사에 무효화()를 호출 할 수 있습니다 크기를 조정하면 전체 크기가 조정됩니다.

이것이 사라지면 흥미로운 점은 this.EditingControlDataGridView.EditingControl.Width와 e.ClipRectangle.Width가 다릅니다. 차이점은 오른쪽에 추가 된 "추가"공간입니다. 만약 내가 동등한 그림을 그리는 것이 허락된다면, 빈 공간이 오른쪽에서 관찰 가능했다.

관련 문제