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

  • SEARCH
  • Home
  • 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 8874579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:45:25+00:00 2026-06-14T18:45:25+00:00

I bind a DataGridView to a (List of ‘Payment’ objects) collection, I am using

  • 0

I bind a DataGridView to a (List of ‘Payment’ objects) collection, I am using RowsAdded Event to Change the back color of the row depending on the status of the payment.
I am using (row.DefaultCellStyle.BackColor) to change the back color, But If I changed the color of the First row, then the color of the second row will be changed also, even though I did NOT change its back color.
and I don’t want to change its back color to (white) because there are some columns that have their own colors.

private void dgvPayment_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {

            DataGridViewRow row = dgvPayment.Rows[e.RowIndex];
            Payment  lPayment = row.DataBoundItem as Payment;
            if (lPayment != null)
                if (lPayment.IsLocked)
                {
                    row.DefaultCellStyle.BackColor = Color.LightPink;
                    row.ReadOnly = true;
                }
        }

how to solve this ?

you can download the source code for here .

  • 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-14T18:45:26+00:00Added an answer on June 14, 2026 at 6:45 pm

    the problem is that when I put the backColor to white, the whole row will become white,I don’t want this , because there are a column(s) which have its own backColor.

    As mentioned here (datagridview-defaultcellstyle-rows-and-columns-priority) :

    It’s probably something internal to DataGridViews, where row styles
    override column styles either explicitly or because row styles are
    applied on top of column styles.

    In addition to setting default styles for the first row and first
    column, try setting the first cell’s style directly, which will
    override ANY default, whether for row or column.

    So I Solved it like this;

    private void dgvPayment_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
            {
                for (int index = e.RowIndex; index <= e.RowIndex + e.RowCount - 1; index++)
                {
                    DataGridViewRow row = dgvPayment.Rows[index];
                    Payment lPayment = row.DataBoundItem as Payment;
                    if (lPayment != null && lPayment.IsLocked)
                    {
                        row.DefaultCellStyle.BackColor = Color.Pink;
                        row.ReadOnly = true;
                    }
                    else
                    {
                        row.DefaultCellStyle = null;
                        row.ReadOnly = false;
                    }
    
    
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an list of objects (PrintJob) that I bind to a DataGridView. Here
If you bind a DataGridview (winform) to a list of objects can you define
I have a List of customers that I'm trying to bind to a DataGridView.
I have a DataGridView that I am trying to bind to a list. I
I have a windows form where I am using DataGridView control. It is bind
I bind a list<> to a datagrid. Then, in the code behind, I change
I have a DataGridView to which I've set a list of objects to the
I tried to bind List<T> to DataGridView . Everything seemed to be ok before
I have a List that I want to bind to a DataGridView in a
In DataGridView, how to bind an array or list (with n elements) to n

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.