Skip to main content Skip to footer

HowTo: Rotate Text in Merged Cells in C1FlexGrid

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 blog explains 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.

Rotate Text in Merged Cells

First of all, 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  
{  

}  

Then, we need to override the CreateCellContent method of the CellFactory class and set the RotateTransform's Angle. You can read more about RotateTransform 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;  
            }  
        }  
    }  

On assigning the above CellFactory object to C1FlexGrid, it would show the Rotated Text in MergedRanges as shown in the image below. Rotate Text in MergedRange Rotate Text in MergedRange For detailed implementation refer to sample DownloadSample_CS DownloadSample_VB

MESCIUS inc.

comments powered by Disqus