Hi,
I searched a lot about changing the DataGridView cell borders. BYTES helped me so I will write down the solution:
1. You should override the class DataGridViewTextBoxCell, and the new class should have a property of type DataGridViewAdvancedBorderStyle, this property you will change from the outside:
2. You will override also the PaintBorder, and Paint methods in a way that they will get the new property instead of the default one.
3. Thats it, all you have to do is to use your own overriden cell class for adding new cells in the rows.
-------------------------------------
here is the overriden class:
class CustomDataGridViewCell : DataGridViewTextBoxCell
{
private DataGridViewAdvancedBorderStyle _style;
public CustomDataGridViewCell(): base()
{
_style = new DataGridViewAdvancedBorderStyle();
_style.Bottom = DataGridViewAdvancedCellBorderStyle.None;
_style.Top = DataGridViewAdvancedCellBorderStyle.None;
_style.Left = DataGridViewAdvancedCellBorderStyle.None;
_style.Right = DataGridViewAdvancedCellBorderStyle.None;
}
public DataGridViewAdvancedBorderStyle AdvancedBorderStyle
{
get { return _style; }
set
{
_style.Bottom = value.Bottom;
_style.Top = value.Top;
_style.Left = value.Left;
_style.Right = value.Right;
}
}
protected override void PaintBorder(Graphics graphics, Rectangle clipBounds, Rectangle bounds, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle)
{
base.PaintBorder(graphics, clipBounds, bounds, cellStyle, _style);
}
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, _style, paintParts);
}
}