dualshck012
Active member
Good Day! I have this code to highlight a duplicated row in datagridview, but cannot make the highlighting work. My datagridview is set to AutoGenerateColumns = true and getting my column name headers from my sql query.
C#:
public void _HIGHLYTSAME(DataGridView dgtable_dmgrphic)
{
for (int currow = 0; currow < dgtable_dmgrphic.Rows.Count - 1; currow++)
{
DataGridViewRow rcompare = dgtable_dmgrphic.Rows[currow];
for (int othrow = currow + 1; othrow < dgtable_dmgrphic.Rows.Count; othrow++)
{
DataGridViewRow row = dgtable_dmgrphic.Rows[othrow];
bool duprow = true;
if (!rcompare.Cells["PROFILE"].Value.Equals(row.Cells["PROFILE"].Value))
{
duprow = false;
break;
}
if (duprow)
{
rcompare.DefaultCellStyle.BackColor = Color.Green;
rcompare.DefaultCellStyle.ForeColor = Color.#fff;
row.DefaultCellStyle.BackColor = Color.Green.;
row.DefaultCellStyle.ForeColor = Color.yellow;
}
}
}
}
Last edited by a moderator: