Posted 24 February 2022, 5:24 am EST
This is done by using a CellStyle.
First you create a named CellStyle and define the borders:
CellStyle styleWithBorder = this.c1FlexGrid.Styles.Add("WithBorder", this.c1FlexGrid.Styles.Normal);
styleWithBorder.Border.Style = BorderStyleEnum.Flat;
styleWithBorder.Border.Color = Color.Red;
styleWithBorder.Border.Width = 2;
styleWithBorder.Border.Direction = BorderDirEnum.Both;
This style has border to the right and the bottom, with red lines of width “2”.
Later, you apply this CellStyle to single cells:
this.c1FlexGrid.SetCellStyle(row, col, styleWithBorder);
You have to set the style to each single cell.
There is one thing to note: the border applies only to the right/bottom border of a cell. To create a top border, you have to create a style with only bottom border (“Border.Direction = BorderDirEnum.Horizontal”) and set this style to the cell above the current cell.
Same for a left border: create a style with only right border (“Border.Direction = BorderDirEnum.Vertical”) and set this style to the cell left to the current cell.
A long time ago, I had created and posted a helper class that used the “OwnerDrawCell” event to draw the borders and had an easier API to create borders. But this forum post is no longer available. If you are interested, I can add it again.
Best regards
Wolfgang