Hi,

I have an ImageColumn in my DataGridView.

I have run a query to return 'commentsGenPosID' from 'myComments' table.

I then want to check if 'commentsGenPosID' matches with 'thisPosID'. 'thisPosID' is a column on the DataGridView.

The column should display an image based on the value of another column. But it does not do this for all matching values. Only for the last entry in the 'myComments' table.

Why is this?
Thanks.

Code:
private void IDMatchesDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
DataGridView dgv = sender as DataGridView;

if ((e.RowIndex != -1) && (e.ColumnIndex != -1))
{
if (e.ColumnIndex == 2)
{
DataRow dr = ((DataRowView)dgv.Rows[e.RowIndex].DataBoundItem).Row;

foreach (DataRow theRow2 in this.myDataSet1.Tables["myComments"].Rows)
{
try
{
int thisPosID = (int)dr[dgv.Columns[3].DataPropertyName];

int commentsGenPosID = (int)theRow2["thisPositionID"];

if (thisPosID == commentsGenPosID)
{
e.Value = Properties.Resources.email_go;
}
else
{
e.Value = Properties.Resources.page_white_horizontal;
}
}
catch (Exception ex)
{
e.Value = Properties.Resources.page_white_horizontal;
}
}
}
}
}