This is a migrated thread and some comments may be shown as answers.

AlternateRowBackground starting on first row

1 Answer 29 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jarred Froman
Top achievements
Rank 1
Jarred Froman asked on 06 Oct 2011, 05:10 PM
We are able to get the alternating row colors to work by setting AlternationCount = 2, however, we would like the alternate background/style to start on the first row.  Is there an easy way of accomplishing this?

Thanks,
-Jarred Froman

1 Answer, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 07 Oct 2011, 09:15 AM
Hello Jarred Froman,

 

You may track the row index and set the background of a row based on your custom logic.
For example you may subscribe to the RadGridView's RowLoaded event and based on the row index you may paint its background, as shown below:


private void radGridView1_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
      {
          if (e.Row is GridViewHeaderRow || e.Row is GridViewNewRow || e.Row is GridViewFooterRow)
              return;
 
          var row = e.Row as GridViewRow;
          int index = this.radGridView1.Items.IndexOf(row.Item as Item);
          if (index % 2 == 0)
          {
              row.Background = new SolidColorBrush(Colors.Red);
          }
          else
          {
              row.Background = new SolidColorBrush(Colors.White);
          }
      }


Furthermore you may also achieve the desired result using StyleSelectors. 


All the best,
Vanya Pavlova
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Jarred Froman
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Share this question
or