Home Forums WinForms controls Xceed Grid for WinForms Help on row color

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #12752 |

    hello

    is it possible to change the backcolor o a row like
    1 yellow
    2 white
    3 yellow
    4 white
    5 yellow
    6 white
    7 …

    and so on.

    It is possible to do it in the standard DataGrid

    Thanks.

    Imported from legacy forums. Posted by rubenalves (had 2916 views)

    User (Old forums)
    Member
    Post count: 23064

    If you’re working in VB.NET, copy this into the grids AddingDataRow event:

    If (e.DataRow.Index Mod 2) = 0 Then
    e.DataRow.BackColor = Color.White
    Else
    e.DataRow.BackColor = Color.Yellow
    End If

    and it should give you the idea.

    If it helps (e.DataRow.Index Mod 2) works out if the rows index is odd (returns 1) or even (return 0), then colours then accordingly.

    can’t help if you’re working in C# though, anyone….

    Imported from legacy forums. Posted by Dr Unken (had 420 views)

    Xceed Support
    Member
    Post count: 5658

    Hello,

    Although the solution provided would work, the order of the backcolor of the datarows would change when the grid is sorted. I would suggest you use the DataRowTemplateStyles property instead to alternate the color of the DataRows. For example:

    gridControl1.DataRowTemplateStyles.Add( new VisualGridElementStyle() );
    gridControl1.DataRowTemplateStyles.Add( new VisualGridElementStyle() );

    gridControl1.DataRowTemplateStyles[ 0 ].BackColor = Color.White;
    gridControl1.DataRowTemplateStyles[ 1 ].BackColor = Color.Yellow;

    The code above assumes that the BackColor property of the DataRowTemplate is NOT set. If it is set, then all the rows will have the backcolor of the DataRowTemplate regardless of the backcolors specified via the DataRowTemplateStyles.

    More information can be found here: http://doc.xceedsoft.com/products/gridNet/doc/sources/datarowtemplate_styles.htm

    I hope this helps!

    Imported from legacy forums. Posted by Jenny [Xceed] (had 4445 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.