DataGridView border

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
 
N

Nicholas Paldino [.NET/C# MVP]

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).
 
R

R.A.F.

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
}

}
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
R

R.A.F.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top