datagridview style

Posted on 2006-04-17
Medium Priority
Last Modified: 2012-06-22
I'm trying to apply some style formatting to a datagridview at the start of my program.  Here is the body of the method which does this:

            foreach (DataGridViewRow row in dataGridView1.Rows)
                if (row.Cells[0].FormattedValue.ToString() != "Blah")
                    row.DefaultCellStyle.BackColor = Color.DarkGray;

This method is called at the very end of my constructor, and does in fact pop the the "IN" message.  The problem is that the cells don't change color as they should.  I have also put a button on my form, and set the event handler to do nothing but call this same method.  For some reason when I click on the button, the cells DO in fact change color as they should.

Does anyone know why I cannot change the backColor of the cells in the constructor, but I can in some random eventHandler?
Question by:ARACK04
1 Comment
LVL 11

Accepted Solution

vo1d earned 2000 total points
ID: 16471308
it seems that the grid uses the property RowTemplate.DefaultCellStyle for painting, if a row is added.
if you want custom painting depending on the value of a cell, i think you will have to use the CellPainting event.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question