On slection change column & row header's background & foreground color

Posted by: pragati-sd-fp on 10 September 2017, 10:57 am EST

  • Posted 10 September 2017, 10:57 am EST

    Hello,
    I need to change the column & row header's background & foreground colors on selection.
    I tried with -

    sheet.SelectionChanged += new EventHandler(sheet_SelectionChanged);

    void sheet_SelectionChanged(object sender, SheetSelectionChangedEventArgs e)
    {
     ((Worksheet)sender).ColumnHeader.Columns[e.Column].Background = new SolidColorBrush(Colors.Blue);
     ((Worksheet)sender).ColumnHeader.Columns[e.Column].Foreground = new SolidColorBrush(Colors.White);
    }

    But, it shows the changed color, when I moved to the next selection. It means it changes, but not reflecting on focus. At the focus it shows orange & when moved to next selection, showing the changed one. Please, check the screenshot attached.

    When cell selected - Blue background & white text will appear for row & column header.
    When selection changed - Previously changed headers will get back to default style & new row, column headers will get in blue & white.

    Please, help.

    Thanks,
    Pragati.  


    2012/10/Column Header color change on selection.JPG
  • Replied 10 September 2017, 10:57 am EST

    Pragati,

    The column header cell has a Background property that determines the normal header cell background color. The control also has the concept of a header selection background color. The header selection background color overrides the header cell background color when the column is selected. Thus, your code to set the cell background color will not affect the selected cells.

    Your code is setting the cell background color when a column is selected but is not clearing the cell background color when the column is unselected. Thus, your assigned background color will remain when you move the selection to a new column.

  • Replied 10 September 2017, 10:57 am EST

    Hello bobbyo,
    Thanks for your reply.
    I'm using the dlls of version 1.0.2012.5155. Other details - VS 10, SL4.

    Will you please provide the sample code?

    Thanks,
    Pragati.
Need extra support?

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

Learn More

Forum Channels