Skip to main content Skip to footer

Customize the style of a protected sheet’s column header in WinForms

Issue:

If the Protect property of SheetView is set to true, the style of the sheet along with headers (row and column, both) become grayed to show the locked state.

However, if the developer wants to modify the style of the column header, then the styling properties specific to locked cells like LockBackColor and LockForeColor do not work if LegacyBehaviors is’ None’. If LegacyBehaviors is set to ‘Style’ then sort indicators get lost.

Therefore, this article shows how to customize the column header style in a protected sheet without losing sort indicators. 

Resolution:

The problem happens because the column renderer is of a GeneralCelltype, so it does not paint the sort icon. It should be an instance of ColumnHeaderRender.

1. Spread’s ColumnHeaderRender does not support changing the LockBackColor/ LockForeColor. Therefore, write a custom ColumnHeaderRender render.

Following is the complete code for the custom ColumnHeaderRender:

2. Define the renderer of each cell in the column header to the custom column header renderer created above:

Tags:

Ruchir Agarwal