The initial task of drawing a DataGridView. Shows black areas

Later editing I noted this as a question of C #, as well as C ++, because the problem occurs in both languages, and the solution, if shown, will most likely be in C # (most of the market).

I am developing an application for .net 2.0 (C ++ is specific, but irrelevant).

This app uses a custom datagridview. This datagridview will sometimes have artifact problems with respect to a DGV area that does not contain cells, as well as a scroll bar. During some resizing actions, a black rectangle will draw at the bottom of the datagridview window, which actually limits the size of the grid. The scrollbar also becomes compressed to fit into an unsupported region. It seems to me that the system believes that the DGV is the wrong size and is drawn into the wrong region.

alt text http://img12.imageshack.us/img12/2213/81356991.jpg

There are only two ways I can find to correct the symptoms:
1. Clicking on a column to resize automatically locks the grid
2. Calling the AutoResizeRows () function in DGV will make a correction (but I believe that this is what is called from point 1).

Some changes to Custom DGV:
1) Configured to handle drag \ drop from multiple lines.
2) Point 1 requires that OnCellPainting be overridden to draw drag lines. A function may be published if it seems symptomatic.
3) Problems always arise when resizing (both manually and automatically can cause a problem), but there is no user code in the resize event.

late editing code for onCellPainting. Other functions overridden in gridview: OnMouseDown, OnCellMouseDown, OnClick, OnMouseMove, OnDragOver, OnDragDrop, OnDragLeave, OnKeyDown, none of which seem symptomatic

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 

* Additional changes None of these features helps to fix the problem, the only thing that fixes it. AFTER a problem occurs - AutoResizeRows (AllCells) // Only AllCells fixes it. It is very slow and undesirable.

Refresh (); UpdateBounds (); Refresh (); Invalidate (); PerformLayout (); ResetBackColor (); ResetBindings (); ResetForeColor (); ResetText (); UpdateStyles ();

+4
source share
4 answers

It seems to me that your control does not correctly display its layout.
Did you pause the link at some point in your code and then never resume?

This will allow your management to function correctly, but not lay out all its components properly.

+7
source

Try setting the .ResizeRedraw property your control to true in the constructor, see if that helps.

From MSDN :

Gets or sets a value indicating whether the control will redraw when resized.

0
source

Try clearing the graphics using the grid background in OnPaint :

 Graphics g = e.Graphics; g.Clear(this.BackColor); 
0
source

I had the same issue caused by some resx files that were not loaded, referenced by mDataGridView_CellPainting events. DataGridView become very slow for resizing.

0
source

All Articles