Home Forums WinForms controls Xceed Grid for WinForms Help on row color Reply To: Help on row color

Xceed Support
Post count: 5658


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)