Skip to main content Skip to footer

How to rotate text within merged cells

When using any Grid control, we generally have a requirement to display rotated text in some column or cell. With C1FlexGrid control, customization is always easy because of its ability to integrate with default .Net classes. This code snippet shows how one can Rotate Text in MergedRanges of C1FlexGrid using CellFactory class. CellFactory class can take data representation to a whole new level. This class provides capability to customize the grid at the cell level and hence can be very helpful in accomplishing certain scenarios.

To accomplish the concept of Transforming Text in MergedRange, lets start by creating a class that inherits from the CellFactory class.

public class myCellfactory : CellFactory  
    {  
        public override void CreateCellContent(C1FlexGrid grid, Border bdr, CellRange rng)  
        {  
            base.CreateCellContent(grid, bdr, rng);  
            var tb = bdr.Child as TextBlock;  

            if (tb != null && rng.Column == 2 || rng.Column == 7 || rng.Column == 8)  
            {  
                ContentPresenter cp = (VisualTreeHelper.GetParent(tb) as ContentPresenter);  
                System.Windows.Media.RotateTransform rotateTransform = new RotateTransform();  
                rotateTransform.Angle = 50;  
                tb.LayoutTransform = rotateTransform;  
                bdr.Background = Brushes.PaleGreen;  
                tb.Foreground = Brushes.Blue;  
            }  
        }  
    }  

WPF FlexGrid Rotate Cell Text in Merged Cells