迟编辑我将其标记为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