Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8401363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:47:13+00:00 2026-06-09T21:47:13+00:00

I am using DataGrid and trying to change the default background color for every

  • 0

I am using DataGrid and trying to change the default background color for every other row (odd number rows have yellow color while even number rows have white color) since the color is too similar to the highlight color.

Here is my code:

MyDataGrid.LoadingRow += delegate(object sender, DataGridRowEventArgs e)
{
    var currentRowContext = e.Row.DataContext;    
    if (currentRowContext.GetType()
                         .GetProperty("OBJECTID")
                         .GetValue(currentRowContext, null)
                         .ToString()]) % 2 == 0)
        {
            e.Row.Background = new SolidColorBrush(Colors.White);
        }
        else
        {
            e.Row.Background = new SolidColorBrush(
                                      new Color() { 
                                                    R = 235, 
                                                    G = 235, 
                                                    B = 0, 
                                                    A = 60 
                                                   });
};
MyDataGrid.UnloadingRow += delegate(object sender, DataGridRowEventArgs e)
{
    e.Row.Background = null;
};

It shows up correctly at first, but after I click any header to sort the records, the color messed up (i.e., not every other row have the same color). I find setting this DataGrid row color is really trick and don’t know if anybody already resolved this issue. How can I keep the alternating colors when sorting records?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:47:15+00:00Added an answer on June 9, 2026 at 9:47 pm

    Is this what you’re trying to achieve ? (meaning every second row gets own color). There’s an implemented alternation code in most relevant wpf controls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF Datagrid populated using a Dataset. I am trying to change
I'm currently using row validation for my datagrid. I'm trying to change the appearance
Using the WPF DataGrid I have the need to change various display and related
im using the WPFToolkit's DataGrid and im trying to get an edit button working,
I'm trying to create a DOJO DataGrid populated using a dojo.data.ItemFileReadStore with very simple
I am using a DataGrid from the WpfToolkit. I have taken the Style resource
I have a Silverlight application that is using a DataGrid. Inside of that DataGrid
We have custom headers in the Silverlight DataGrid using the ContentTemplate. We've got a
I have a ASPX.NET DataGrid and im trying to USE a select LIKE 'X'%
I'm using spring-roo trying to use dojox.grid.DataGrid. The page renders as a plain table.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.