DataGridView border

  • Thread starter Thread starter R.A.F.
  • Start date Start date
R

R.A.F.

Hi,

I derived a custom control from DataGridView class.
When my DataGridView borderStyle is equal to FixedSingle, i would like
to replace this Black pen by a user pento allow him to change the border
color (but only when borderStyle is = FixedSingle).

how can i change the pen and redraw the border ?

thx.

RAF
 
RAF,

If you are going to do this, I would recommend overriding the OnPaint
method. In it, you would call the base, to allow the grid to paint itself.

Then, you would draw the border in the custom color, if the border style
is FixedSingle, using the appropriate pen (you will have access to the
Graphics instance to draw on).
 
this is what i will do because i already plan it like that...but in
fact, i have a little issue.

my DataGridView is just the renderer of my class ARGrid.

public class ARGrid : UserControl
{
....
private DataGridView m_dgv;
....

protected override virtual OnPaint(EventArgs e)
{
// here is should add the custom painting border action... but this
paint method is from my UserControl and not my DataGridView
}

}
 
RAF,

Instead of overriding the OnPaint method of the user control, you could
just subscribe to the Paint event on the DataGridView, and then put the code
to paint the border in there.

Or, you can derive a class from DataGridView, override its OnPaint
method, and then put that on your control.
 
Nicholas said:
RAF,

Instead of overriding the OnPaint method of the user control, you could
just subscribe to the Paint event on the DataGridView, and then put the code
to paint the border in there.

I will do that solution because the second one below, force me to have
the property from DataGridView that i do not want to xpose to user for now.
 
Back
Top