Set Sheet Alternating Row Style

Posted by: nathan.hanson on 21 October 2021, 6:20 pm EST

  • Posted 21 October 2021, 6:20 pm EST

    I have set up a StyleInfo object and set its background to AliceBlue. I would like to apply it to every other row of my ActiveSheet. It’s expensive to loop through all of the rows and set the StyleName for each one. Is there a faster way? Here’s some sample code:

    
                // Set up our althernating row style
                StyleInfo alternateRowStyle = new StyleInfo();
                alternateRowStyle.Name = "alt";
                alternateRowStyle.FontSize = 13;
                alternateRowStyle.Background = Brushes.AliceBlue;
    
                Spread.Sheets[0].NamedStyles = new StyleInfoCollection();
                Spread.Sheets[0].NamedStyles.Add(alternateRowStyle);
    
                //Applying the style this way seems expensive. Is there a better way?
                for (int i = 1; i < Spread.Sheets[0].RowCount; i += 2)
                    Spread.Sheets[0].Rows[i].StyleName = alternateRowStyle.Name;
    
    
    

    Thanks!

  • Posted 22 October 2021, 1:28 am EST

    Hi,

    Sorry, but there is no direct way to set alternative-row-color in Spread for WPF.

    However, we can do the same in WinForms.

    https://www.grapecity.com/spreadnet/docs/v14/online-win/spwin-rowcolalt.html

    Thanks,

  • Posted 22 October 2021, 11:29 am EST

    Thank you for the response. We’re moving away from WinForms to adopt WPF, so I guess I’ll just keep using my for loop to set every other row style. Thanks!

Need extra support?

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

Learn More

Forum Channels