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
close icon

Alternating Row Colors.

Is there an easy way to alternate the row color in a data bound grid? Scott

1 Reply

CB Clay Burch Syncfusion Team July 16, 2002 03:02 PM UTC

Normally, we would recommend you handle PrepareViewStyleInfo to alternately color rows, but in the current release (RC2) of GridDataBoundGrid, this event is not being fired. So, for the time being, you can do this by handling QueryCellInfo instead. Here are some code snippets.
//hook the handler in Form_Load...
this.gridDataBoundGrid2.Model.QueryCellInfo += new GridQueryCellInfoEventHandler(HandleQueryCellInfo);

//the handler
private void HandleQueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
	if(e.ColIndex > 0 && e.RowIndex > 0)
	{
		if(e.RowIndex % 2 == 0)
			e.Style.BackColor = Color.Red;
		else 
			e.Style.BackColor = Color.Blue;
		e.Handled = true;
	}
}
	
            

Loader.
Live Chat Icon For mobile
Up arrow icon