Solved

painting individual datagridview cells in visual c#

Posted on 2006-10-21
2
3,307 Views
Last Modified: 2008-01-09
i am creating a datagridview that is populated like this:

DataGridViewRow Row = new DataGridViewRow();
Row = new DataGridViewRow();

DataGridViewCell[] Cells = new DataGridViewCell[2];

Cells[0] = new DataGridViewTextBoxCell();
Cells[0].Value = " ";
Cells[1].Style.BackColor = Color.FromArgb(0, 0, 0);
Cells[1] = new DataGridViewTextBoxCell();
Cells[1].Value = " ";
Cells[1].Style.BackColor = Color.FromArgb(0, 0, 0);

Row.Cells.AddRange(Cells);
dataGridView1.Rows.Add(Row);

and later in the code, this datagridview gets populated with data. when the cell gets populated with data, the cell will change color. when there is no data for the cell, it will revert back to the previous color.

the problem i am facing is there are 1000 rows in this datagridview, and when i change the color on some of the cells (reverting the color back) it seems to be painting the whole datagridview every time...i can see the whole datagridview flicker when it updates.

so my question is:
how can i JUST paint the individual cell and not the whole datagridview when one cell changes color?

thanks in advance.
0
Comment
Question by:jumpmanjay
2 Comments
 
LVL 6

Accepted Solution

by:
e1v earned 500 total points
ID: 17787092
You could try do set DoubleBuffered true for your dataGridView, but since it's a protected property you have derive from datagridview and use the derived datagridview.

public class CustomDataGridView : DataGridView
{
  public CustomDataGridView() : base()
  {
    base.DoubleBuffered = true;
  }
}

This will reduce flickering a lot, but it's not answering your question since the whole visible datagridview still updates (noticeable on slow systems).
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now