The Syncfusion native Blazor components library offers 70+ UI and Data Viz web controls that are responsive and lightweight for building modern web apps.
.NET PDF framework is a high-performance and comprehensive library used to create, read, merge, split, secure, edit, view, and review PDF files in C#/VB.NET.
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;
}
}
}
ADAdministrator Syncfusion Team 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