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.
Unfortunately, activation email could not send to your email. Please try again.

Alternating Row Colors

Thread ID:

Created:

Updated:

Platform:

Replies:

2985 Feb 24,2003 02:31 PM Feb 24,2003 06:09 PM Windows Forms 1
loading
Tags: GridControl
Curtis Koppang
Asked On February 24, 2003 02:31 PM

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 06:09 PM

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

CONFIRMATION

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.

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.

;