Borders() function in ActiveX

Posted by: arcady on 24 February 2022, 2:23 am EST

  • Posted 24 February 2022, 2:23 am EST

    Hello,

    I need an equivalent of setting Borders(x,y) in a flexGrid cell range.

    The code in our activeX solution is this:

    ole_1.object.Range(i + 1, cols - 1, i+4, cols - 1).Borders(3,2)

    How do we do it in the winforms?

  • 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

  • Posted 25 February 2022, 7:07 am EST

    Hi,

    As suggested by Wolfgang, you can create a new CellStyle by using the C1FlexGrid.Styles.Add method and customize its borders using the Border property of the CellStyle. Then you can apply this CellStyle to a particular cell by using the C1FlexGrid.SetCellStyle method.

    If you want to apply the CellStyle to a CellRange, you can get the CellRange from the Grid by using the C1FlexGrid.GetCellRange method and apply the Same CellStyle to the Style property of the CellRange.

    By default, the border is applied to only the Right and bottom border of a cell. If you want to apply styles to all the borders of a cell, you will need to manually draw the borders by using the OwnerDrawCell event. Kindly refer to the Product sample CellBorders at location \Documents\ComponentOne Samples\WinForms\v4.5.2\FlexGrid\CS\ which uses the OwnerDrawCell event to draw manually borders on a Cell/CellRange

    You can also refer to the documentation link below for more information related to C1FlexGrid.

    https://www.grapecity.com/componentone/docs/win/online-flexgrid/C1.Win.C1FlexGrid.4.5.2~C1.Win.C1FlexGrid.C1FlexGrid.html

    Regards.

    Avnish

  • Posted 25 February 2022, 1:41 pm EST

    I created a github project with the “border painter” helper class:

    https://github.com/WolfgangHG/C1FlexGridEnhancements/tree/master/C1FlexGrid452BorderPainter

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels