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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:47:54+00:00 2026-06-04T09:47:54+00:00

We use the CellFormatting event to colour code cells in various grids all over

  • 0

We use the CellFormatting event to colour code cells in various grids all over our application.

We’ve got some generic code which handles export to Excel (and print) but it does it in Black & White. Now we want to change this and pick up the colour from the grids.

This question & answer has helped (and it works) … except there’s a problem with larger grids that extend beyond a single screen. The portions of the grid which haven’t yet been displayed on screen are (logically) never getting their CellFormatting code fired, and so their underlying colour never gets set. As a result, in Excel, the colour coding fizzles out half way down the page.

Seems there are three solutions:

1) Tell the user he has to scroll to all parts of the grid before doing an Export to Excel. Ha! Not a serious solution

2) Programmatically scroll to all parts of the grid before doing an Export to Excel. Only slighly less horrible than (1)

3) In our Export to Excel code, fire something at the top which tells the DataGridView to paint/format its entire area e.g.

  MyDataGridView.FormatAllCells()

Is there something that does something like this???

Oh, and there is a fourth option but this will involve touching a massive amount of existing code:

4) Stop using CellFormatting event, format the cells at load time. Problem with this is we’d have to retool every grid in our application since CellFormatting is the way we’ve done it since year dot.

  • 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-04T09:47:56+00:00Added an answer on June 4, 2026 at 9:47 am

    Assuming, as @DavidHall suggests, there is no magic .FormatAllCells our only option is to stop using CellFormatting.

    However, new problem here is that applying cell style formatting during load doesn’t seem to have any effect. Lots of posts out there if you Google it. Also they point out that if you put the same code under a button on the form and click it after loading (instead of in the load, the code will work … so the grid has to be visible before styling can apply). Most advice on the topic suggests you use … drumroll … CellFormatting. Aargh!

    Eventually found a post which suggests using the DataBindingComplete event of the grid. And this works.

    Admittedly, this solution is a variant of my unwanted option “4”.

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

Sidebar

Related Questions

Use a hidden field will fix my issue... i got it.. Hi All, I
use case is simple: I want to run some boiler plate code before each
If we've applied styling ( e.CellStyle.BackColor say) to some rows via the CellFormatting event
Use case: I've just entered insert mode, and typed some text. Now I want
Use case example: Client A comes to request sales information, enters their zip code
Use of || (or) I got so many values which I need to compare
Use case: 3rd party application wants to programatically monitor a text file being generated
Use case: we have some project meta-data files which we want tracked, but are
use Parallel::ForkManager; use LWP::Simple; my $pm=new Parallel::ForkManager(10); our $a =0; @LINK=( 10,203, 20, 20
use this code, in the Preferences activity, to know when the reset preference has

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.