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 8618241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:03:37+00:00 2026-06-12T06:03:37+00:00

I have a table an some values on it. If the Row Cell Name

  • 0

I have a table an some values on it. If the Row Cell “Name” is not empty change color of background to violet.

Name    ID    Customers

Niky    1     yes       // here change background to violet
        2     no
Donna   3     yes       // here change background to violet
Baka    4     no        // here change background to violet
        5     yes
        6     no

I have tried this code but i doesnt work, dont know why:

 foreach (DataGridViewRow row1 in dataGridView1.Rows)
        {
            if (row1.Cells[0].Value != null)
            {
                row1.DefaultCellStyle.BackColor = Color.Violet;
            }
        }
  • 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-12T06:03:38+00:00Added an answer on June 12, 2026 at 6:03 am

    The usual place to put this sort if code in within the DataBindingComplete event handler, either attach the event as below or using the designer:

    dataGridView1.DataBindingComplete += new DataGridViewBindingCompleteEventHandler(dataGridView1_DataBindingComplete);
    

    Then in the handler you have something like this:

    void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
    {
        foreach (DataGridViewRow row1 in dataGridView1.Rows)
        {
            if (row1.Cells.Cast<DataGridViewCell>().Any(c => c.Value == null || string.IsNullOrWhiteSpace(c.Value.ToString())))
            {
                row1.DefaultCellStyle.BackColor = Color.Violet;
            }
            else
            {
                row1.DefaultCellStyle.BackColor = Color.White;
            }
        }
    }
    

    In the code above I’ve changed your original code to now looks at all cells rather than just the first.


    You can also put the code in the CellFormatting event.

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

Sidebar

Related Questions

I have a table with some values. The first row and first column contain
I have a data table which already has some values, plus it is getting
I'm having some trouble comparing values found in VARCHAR fields. I have a table
I have some problem whith such mysql_query INSERT INTO table VALUES ('', CURDATE()-1) why
Fiddle: http://jsfiddle.net/MhWm5/16/ I have some dynamically generated table rows/values with dynamic IDs <td class=control-group>
I have some table structure: <tr class=row-2><tr> <tr class=row-3>..<tr> <tr class=row-4>..<tr> <tr class=row-5>..<tr> <tr
I'm doing some manipulation and retrieval of values stored in a table. Each row
I have some JavaScript that creates a row in a table and adds cells
I have made a table and contents some values, I have a button coding
I have a table that has some 50 rows. The last cell of each

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.