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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:07:46+00:00 2026-05-23T18:07:46+00:00

i used code like this to change color of cell but properties applying only

  • 0

i used code like this to change color of cell but properties applying only after mouse click but i want change color after form loaded

Used Code

    private void dataGridView1_RowValidated(object sender, DataGridViewCellEventArgs e)
    {
        for (int i = 0; i < 5; i++)
        {
            int j = 6;
            DataGridViewCellStyle CellStyle = new DataGridViewCellStyle();
            CellStyle.ForeColor = Color.Red;
            dataGridView1[j, i].Style = CellStyle;
        }
    }
  • 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-05-23T18:07:47+00:00Added an answer on May 23, 2026 at 6:07 pm

    Remove that code from dataGridView1_RowValidated and add it to form Load event instead:

    Add this code in the form constructor:

    public Form1()
    {
        InitializeComponents();
    
        this.Load += OnFormLoad;
        this.dataGridView1.Sorted += OnDataGridSorted;
    }
    
    private void OnFormLoad(object sender, EventArgs e)
    {
        UpdateDataGridViewColor();
    }
    
    private void OnDataGridSorted(object sender, EventArgs e)
    {
        UpdateDataGridViewColor(); 
    }
    
    private void UpdateDataGridViewColor()
    {
        for (int i = 0; i < 5; i++)
        {
            int j = 6;
            DataGridViewCellStyle CellStyle = new DataGridViewCellStyle();
            CellStyle.ForeColor = Color.Red;
            dataGridView1[j, i].Style = CellStyle;
        }
    }
    

    Note also you can add form Load event by double click on the form designer..

    Edit: you stated in comments that when you click column to sort the applying color will removed. to fix that add this.dataGridView1.Sorted += OnDataGridSorted; event so whenever sorted is done the new style is applied. the code above updated. “btw: I don’t tested it, till me if it not worked..”

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

Sidebar

Related Questions

I have used code like this: http://msdn.microsoft.com/en-us/library/dw70f090.aspx to access database before when working in
I am reading a book in which author used a code like this public
I've used this code to have a like btn on my site: <iframe src=http://www.facebook.com/plugins/like.php?href=URL_OF_YOUR_WEBSITE&amp;send=false&amp;layout=standard&amp;width=450&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font&amp;height=80&amp
Emacs and Java change propagation Hi, I'm mostly used to code in IDE like
This code used to return my local ip address as 192.xxx.x.xxx but now it
This code used to work but doesnt any more. i used a breakpoint, and
<table style=width: 100%; background-color: #B5C7DE> i have this table and want to change the
I used a theme to change the colors of my code and background, but
I want to change the color of a 'th' element after I make a
I want to change the color of human skin to blue, like in the

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.