AlternateRowBackground starting on first row

2 posts, 0 answers
  1. Jarred Froman
    Jarred Froman avatar
    57 posts
    Member since:
    Aug 2008

    Posted 06 Oct 2011 Link to this post

    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
  2. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 07 Oct 2011 Link to this post

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

Back to Top