Hi,

Using the CellFormatting Event causes my Desktop Application to freeze.

The problem seems to be caused by looping through the DataTable.

How can I avoid this problem? Is there a better method?
Thanks.


Code:
private void cPDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if ((e.RowIndex != -1) && (e.ColumnIndex != -1))
{
if (e.ColumnIndex == 2)
{
foreach (DataRow theRow2 in this.rDataSet1.Tables["RComments"].Rows)
{
try
{
int commentsCPPosID = (int)theRow2["CPPositionID"];
int cPPosID = (int)cPDataGridView[3, e.RowIndex].Value;
if (cPPosID == commentsCPPosID)
{
e.Value = Properties.Resources.email_go;
return;
}
else e.Value = Properties.Resources.page_white_horizontal;
}
catch (Exception ex)
{
e.Value = Properties.Resources.page_white_horizontal;
}
}
}
}
}