Changing ColumnHeader.DefaultStyle

Posted by: asystems on 8 September 2017, 3:14 pm EST

  • Posted 8 September 2017, 3:14 pm EST

    Hello.

    I am trying to change the column header style of a spread with the following code:

    public static TextCellType ColHeaderCellType { get; set; }

    static Form1()
    {
    ColHeaderCellType = new TextCellType();
    ColHeaderCellType.StringTrim = StringTrimming.EllipsisCharacter;
    ColHeaderCellType.WordWrap = false;
    ColHeaderCellType.Multiline = true;
    }
    public Form1()
    {
    InitializeComponent();
    fpSpread1.ActiveSheet.ColumnHeader.DefaultStyle.CellType = ColHeaderCellType;
    }


    It works fine but the back color of the header column row is changed from the default and the borders in the headers are not shown anymore.
    Is there a way to change ColumnHeader.DefaultStyle.CellType while keeping the background color and the borders ?

    Thanks.

    Jean-Christophe.
  • Replied 8 September 2017, 3:14 pm EST

    Hello,

    I would like to inform you that if we change the CellType of a column header in spread sheet, it ignores all the basic properties which were applied at the time of rendering this column header and vice-versa. This is a by-design behavior.

    Note: We can apply either the basic styles while rendering the column headers or change their CellType and set its properties later.

    Hope it clarifies.

    Thanks & Regards,
    Pragati Kaushik
  • Replied 8 September 2017, 3:14 pm EST

    Thank you for your answer.

    Unfortunately it does not help me a lot...
    Can you please tell me how I can reapply style elements after changing the cell type : sort indicators, borders and back color.

    A sample project would be great.

    Thanks again.

    Jean-Christophe.
  • Replied 8 September 2017, 3:14 pm EST

    Hi,

    Can you describe more about the requirements you have for the header cells that can't be satisfied by EnhancedColumnHeaderRenderer? Why do you want to set the cell type in the header cells?

    Currently only ColumnHeaderRenderer and its derived classes are the only ones which implement support for drawing the sort and filter indicators. Although other cell types are valid implementations of IRenderer and can technically work to draw the header cells, they really aren't designed for that. And the header cells can't be edited, so the IEditor implementation in the cell type can't be used.

    If you want to make the header cells do something not currently supported, the best way is to inherit a class from EnhancedColumnHeaderRenderer and extend it to support the requirement.

    Regards,
    -Sean
  • Replied 8 September 2017, 3:14 pm EST

    Thanks for your answer.


    What I want to achieve is very simple: disable word wrap, set StringTrim to StringTrimming.EllipsisCharacter and MultiLine to true for all the columns headers of a spread.

    I followed the suggestion made in this thread: http://sphelp.grapecity.com/groups/topic/column-header-text-wordwrap-farpoint-win-textrenderer-dll/

    But as I said in a previous message, borders, sort indicators and back color are lost.

    I will take a look at EnhancedColumnHeaderRenderer class.

    Thanks.

    Jean-Christophe.
  • Replied 8 September 2017, 3:14 pm EST

    I took a look at the EnhancedColumnHeaderRenderer class.

    It contains one property I can set : WordWrap and that's all.
    It does not contain any property like StringTrimming and MultiLine which I need.

    But may be I did not understand your suggestion.
    Please provide me some more details about the way I can resolve my issue.

    Thanks.

    Jean-Christophe.
  • Replied 8 September 2017, 3:14 pm EST

    Hi Jean-Christophe,

    I'm sorry that I was not clear -- here is what I mean:


    public class MyColumnHeaderRenderer : EnhancedColumnHeaderRenderer
    {
    public MyColumnHeaderRenderer() : base()
    {
    WordWrap = false;
    }
    public override void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, object value, bool isSelected, bool isLocked, float zoomFactor)
    {
    base.PaintCell(g, r, appearance, null, isSelected, isLocked, zoomFactor);
    ElementWindowless.DrawRotatedText(g, value as string, appearance.Font, appearance.ForeColor, new RectangleF(r.X, r.Y, r.Width, r.Height), ToHorizontalAlignment(appearance.HorizontalAlignment), ToVerticalAlignment(appearance.VerticalAlignment), FarPoint.Win.TextOrientation.TextHorizontal, false, true, System.Drawing.Text.HotkeyPrefix.None, StringTrimming.EllipsisCharacter, r.Height, false, 0, 0, false);
    }
    }

    You can override the EnhancedColumnHeaderRenderer's PaintCell method to draw the text with your requirements (no word wrap, multiline, string trimming), and let the base class handle the drawing of the indicators.

    Hope that helps!

    Regards,
    -Sean
  • Replied 8 September 2017, 3:14 pm EST

    Hello,

    I would like to inform you that if we want to set the sort indicators, borders, backcolor and other basic properties of column header, then we cannot change the CellType of its column header in Spread sheet.

    Hope it clarifies.

    Thanks & Regards.
  • Marked as Answer

    Replied 8 September 2017, 3:14 pm EST

    Many thanks Sean,

    The code you provide works perfectly.
    Sorry, I should have think of overriding the PaintCell method.

    Thanks again for your patience.

    Jean-Christophe.
Need extra support?

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

Learn More

Forum Channels