Skip to main content Skip to footer

Setting Column Header Style for Active Cell

Spread for Silverlight allows you to implement lot of customization. In this blog I will explain how we can set the style for Spread cells in header. Setting style for headers is not a big task as there is already a DefaultStyle property for ColumnHeader class which you can use to set style for ColumnHeader cells. Here is an an example on how to do that: First create a StyleInfo class object and set it's properties like Background and Foreground.


GrapeCity.Windows.SpreadSheet.Data.StyleInfo si = new GrapeCity.Windows.SpreadSheet.Data.StyleInfo();  
si.Foreground = new SolidColorBrush(Colors.Orange);  
si.BackGround = new SolidColorBrush(Colors.Green);  

Now assign this StyleInfo object to Column header DefaultStyle and see the result in image.


gcSpreadSheet1.ActiveSheet.ColumnHeader.DefaultStyle = si;  

What if we want to change the style for header with active cell. It means instead of setting the style for entire the Column Header row or Row Header column, we want to set the highlighting style for headers for active cells. It will be clear with this image. To achieve this we will have to create a custom sheet inheriting WorkSheet class and override cellstyle logic.


public class MyWorksheet : Worksheet  
{  
  public override StyleInfo GetActualStyleInfo(int row, int column, SheetArea sheetArea)  
  {  
    var style = base.GetActualStyleInfo(row, column, sheetArea);  
    if (column == this.ActiveColumnIndex & & sheetArea == SheetArea.ColumnHeader)  
    {  
      style.Foreground = new SolidColorBrush(Colors.Orange);  
      style.FontStyle = FontStyles.Italic;  // Set the font style for active cell column header  
    }  
    return style;  
  }  
}  

We also need to invalidate rows to repaint the header row on every change of active cell and active column. We can do that in Entercell event using the code as follows:


void gcSpreadSheet1_EnterCell(object sender, GrapeCity.Windows.SpreadSheet.UI.EnterCellEventArgs e)  
{  
  this.gcSpreadSheet1.InvalidateRows(0, 1, SheetArea.ColumnHeader);  
}  

Look at this outcome image for the above customization. Refer to the attached samples for complete implementation: Download VB.Net Sample Download C# Sample

MESCIUS inc.

comments powered by Disqus