遲編輯我將其標記爲C#問題以及C++,因爲問題以兩種語言呈現,並且解決方案如果顯示很可能在C#(大部分市場)中。派生的DataGridView繪圖問題。顯示黑色區域
我一直在.net 2.0下開發一個應用程序(C++是特定的,但不相關)。
此應用程序使用自定義導出的datagridview。此datagridview偶爾會出現有關不包含單元格的DGV區域以及滾動條的嚴重製造問題。 在某些調整大小操作期間,黑色矩形將繪製在datagridview的底部,這實際上會限制網格的大小。滾動條也會縮小以適應非固定區域。在我看來,系統認爲DGV是錯誤的大小,並且正在進入錯誤的地區。
alt text http://img12.imageshack.us/img12/2213/81356991.jpg
只有兩種方式我能找到解決的症狀:
1.單擊列來調整將自動修復電網
2.調用AutoResizeRows()函數在DGV會做的修復(但我相信是從點1被稱爲)。
對定製DGV的一些修改:
1)配置爲處理多行拖放。
2)要點1需要重寫OnCellPainting來繪製拖動線。如果看起來有症狀,可以發佈功能。
3)問題總是發生在調整大小(手動和自動都會導致問題),但resize事件中沒有自定義代碼。
延遲編輯 onCellPainting的代碼。在GridView覆蓋其他功能:其中沒有onmousedown事件,OnCellMouseDown,的OnClick,的OnMouseMove,OnDragOver,OnDragDrop,OnDragLeave,onkeydown事件,似乎對症
protected: [DebuggerStepThrough()]
virtual System::Void OnCellPainting(DataGridViewCellPaintingEventArgs ^e) override
{
//draws red drag/drop target indicator lines if necessary
if (this->AllowDrop && _DragDropCurrentIndex > -1 && ShowDragLines)
{
System::Drawing::Pen ^p = gcnew Pen(System::Drawing::Color::Navy, 3);
//row drag/drop
if (e->RowIndex == _DragDropCurrentIndex &&
_DragDropCurrentIndex <= this->RowCount)
{
//if this cell is in the same row as the mouse cursor
e->Graphics->DrawLine(
p,
e->CellBounds.Left,
e->CellBounds.Top - 1,
e->CellBounds.Right,
e->CellBounds.Top - 1);
} //end if
if(e->RowIndex == this->Rows->Count - 1 &&
_DragDropCurrentIndex == Int32::MaxValue)
{
e->Graphics->DrawLine(
p,
e->CellBounds.Left,
e->CellBounds.Bottom + 1,
e->CellBounds.Right,
e->CellBounds.Bottom + 1);
}
} //end if
DataGridView::OnCellPainting(e);
} //end OnCellPainting
*更多的編輯 沒有這些工作來擺脫這個問題,只修復問題的原因是AutoResizeRows(AllCells)//只有AllCells修復它。這是非常緩慢和不可取的。
Refresh(); UpdateBounds(); Update(); Invalidate(); PerformLayout(); ResetBackColor(); ResetBindings(); ResetForeColor(); ResetText(); UpdateStyles();
標籤爲C#但作者聲明VC++ - 可以有人有足夠的rep repr重新請? – 2009-09-08 14:35:09
你可以發佈OnCellPainting代碼嗎?這當然似乎是一個可能的候選人。如果你只是評論這個覆蓋,你還看到這個問題的調整? – MusiGenesis 2009-09-10 12:41:09
使用OnCellPainting更新原始文章。評論重寫的功能,仍然沒有運氣。 – greggorob64 2009-09-10 12:59:15