Does anybody know how to change the border color of a datagridview in a windows form?
You can't, it is drawn with the color that the user selected in her preferred theme, selected in Control Panel's Display applet. Overriding the user preference is risky, but you can do so by drawing it yourself. Set the DGV's BorderStyle property to None and draw a border yourself in the form's OnPaintBackground() method. For example:
protected override void OnPaintBackground(PaintEventArgs e) {
base.OnPaintBackground(e);
Rectangle rc = new Rectangle(dataGridView1.Left - 1, dataGridView1.Top - 1,
dataGridView1.Size.Width + 1, dataGridView1.Size.Height + 1);
e.Graphics.DrawRectangle(Pens.Fuchsia, rc);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With