kryptonDataGridView.CellBorderStyle not working

580 Views Asked by At

If I have a normal DataGridView and I want to show only the horizontal lines, I apply the following code:

dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.SingleHorizontal;

Using the UI template Krypton for WinFroms, it is not working for me. I use:

kryptonDataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.SingleHorizontal;

And the lines still appear!

Did anyone come across this problem and solve it?

1

There are 1 best solutions below

0
On

I know this is an old question, but I hope you can still find this useful:

Why your code doesn't work:

Well, KryptonDataGridView inherits from the DataGridView WinForms control, and by looking at the source code, you'll find that KryptonDataGridView.CellBorderStyle simply gets or sets the value of base.CellBorderStyle which are not the same borders displayed by KryptonDataGridView.

A lot of the inherited properties doesn't have an effect on Krypton controls (the Font property, for example). But in most cases, Krypton provides an alternative (with more features usually).

Solution:

To replicate the behavior of DataGridView.CellBorderStyle, with KryptonDataGridView, you should use the DataCell.Border.DrawBorders property of the appropriate State:

using ComponentFactory.Krypton.Toolkit;
//

kryptonDataGridView1.StateCommon.DataCell.Border.DrawBorders =
    PaletteDrawBorders.TopBottom;

Result:

KryptonDataGridView

Hope that helps.