Skip to main content Skip to footer

How to draw dotted cell borders in C1FlexGrid

This implementation shows Dotted Cell Borders in C1FlexGrid for WPF. Concept of Dotted Cell Borders uses VisualBrush. It has a property Visual which allows to define new content inside the border. We can define a Rectagle as border content which can be customized to show dotted lines using the property 'StrokeDashArray' that indicates the pattern of dashes and gaps that is used to outline shapes. Above concept can be easily applied on individual cells using CellFactory. Refer to the code snippet below for the implementation.

This implementation shows Dotted Cell Borders in C1FlexGrid for WPF. Concept of Dotted Cell Borders uses VisualBrush. It has a property Visual which allows to define new content inside the border. We can define a Rectagle as border content which can be customized to show dotted lines using the property 'StrokeDashArray' that indicates the pattern of dashes and gaps that is used to outline shapes. Above concept can be easily applied on individual cells using CellFactory. Refer to the code snippet below for the implementation.


public class MyCellFactory : C1.WPF.FlexGrid.CellFactory  
{  
  List<C1.WPF.FlexGrid.CellRange> crw = new List<C1.WPF.FlexGrid.CellRange>();  
  public MyCellFactory()  
  {  
     crw.Add(new C1.WPF.FlexGrid.CellRange(0,0));  
     crw.Add(new C1.WPF.FlexGrid.CellRange(1,1));  
     crw.Add(new C1.WPF.FlexGrid.CellRange(2,2));  
     crw.Add(new C1.WPF.FlexGrid.CellRange(3,3));          
  }  

  public override Border CreateCellBorder(C1.WPF.FlexGrid.C1FlexGrid grid, C1.WPF.FlexGrid.CellType cellType, C1.WPF.FlexGrid.CellRange rng)  
  {  
     Border bdr = base.CreateCellBorder(grid, cellType, rng);  

     if (cellType == C1.WPF.FlexGrid.CellType.Cell)  
       if (crw.Contains(rng))  
       {  
           VisualBrush vb = new VisualBrush();  
           vb.Visual = new Rectangle() { Height = 10, Width = 40, Stroke = new SolidColorBrush(Colors.Red), StrokeDashArray = new DoubleCollection() { 1.0 } };  

           bdr.BorderThickness = new Thickness(2, 2, 2, 2);  
           bdr.BorderBrush = vb;                  
       }  

    return bdr;  
  }  

}  

Once we assign the above CellFactory object to C1FlexGrid, it would show the dotted cells as shown in the image below.

WPF FlexGrid Cell Borders