I use C #, Winforms and .Net 3.5
My form has its own DataGridView(with double buffering to prevent flickering during cell formatting events, as shown here ). When I search the database, I link the resulting dataset to datagridview.
I handle the event CellFormattingto draw strings of a certain color, depending on their data.
My DataGridView Code:
resultsGridView.DataSource = results.DefaultViewManager.DataSet.Tables[0];
resultsGridView.AlternatingRowsDefaultCellStyle.BackColor = Color.AliceBlue;
resultsGridView.BorderStyle = BorderStyle.Fixed3D;
resultsGridView.CellFormatting += new DataGridViewCellFormattingEventHandler(resultsGridView_CellFormatting);
My CellFormatting Code:
void resultsGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
int rowIndex = e.RowIndex;
DataGridViewRow therow = resultsGridView.Rows[rowIndex];
if ((bool)therow.Cells["Sealed"].Value == true)
{
therow.DefaultCellStyle.BackColor = Color.Pink;
}
if (therow.Cells["Database"].Value as string == "PNG")
{
therow.DefaultCellStyle.BackColor = Color.LightGreen;
}
}
Everything works fine, except that when I process CellFormatting, the drawing event of the whole form seems to be disabled. The cursor stops flashing in the text box, and the menu form looks like this:

, . , , , , . , , , .
resultsGridView.CellFormatting resultsGridView.CellFormatting datagridview .
- ?