We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Alternating Row Colors

Thread ID:





2985 Feb 24,2003 07:31 PM UTC Feb 24,2003 11:09 PM UTC WinForms 1
Tags: GridControl
Curtis Koppang
Asked On February 24, 2003 07:31 PM UTC

I want to alternate row colors and am using the code shown (below) in the FAQ or on the forum, don't recall which. Anyway, this looks terrible! I have a hierachy I am showing and this code does not take that into consideration. So it is possible that items at the same level in the hierarchy are different colors. I want the coloring to be reset for each level in the hierarchy. So the first child at any given depth is always the same color. Other grids just make this happen by setting a top level property, so perhaps this is a suggestion for a future feature. For the time being I would be happy with a work-around. Tx, curt private void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e) { if ( e.Style.CellType.CompareTo( "TextBox") == 0 || e.Style.CellType.CompareTo( "CheckBox") == 0) { if ( e.ColIndex > 0 && e.RowIndex > 0) { if ( e.RowIndex % 2 == 0) e.Style.BackColor = Color.LightBlue; else e.Style.BackColor = Color.White; } } }

Administrator [Syncfusion]
Replied On February 24, 2003 11:09 PM UTC

Hi Curtis, try to get the GridBoundRecordState and the position within the nested table. Example: private void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e) { GridDataBoundGrid grid = sender as GridDataBoundGrid; if (grid != null && e.ColIndex > 1) { if (grid.IsShowCurrentRow(e.RowIndex) && !grid.CurrentCell.HasCurrentCellAt(e.RowIndex, e.ColIndex)) { e.Style.BackColor = SystemColors.Highlight; e.Style.TextColor = SystemColors.HighlightText; } else { GridBoundRecordState rs = grid.Binder.GetRecordStateAtRowIndex(e.RowIndex); switch (rs.LevelIndex) { case 0: if ( rs.Position %2 == 0) e.Style.BackColor = Color.LightBlue; else e.Style.BackColor = Color.White; break; case 1: if ( rs.Position % 2== 0) e.Style.BackColor = Color.DarkBlue; else e.Style.BackColor = Color.Yellow; break; default: if ( rs.Position %2 == 0) e.Style.BackColor = Color.Blue; else e.Style.BackColor = Color.Fuchsia; break; } } } } We'll add support for automatic alternate row colors together with many other improvements for hierarchical display in the 2.0 version. Stefan


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon