How to highlight rows in datagriedview that not in datatable rows in c#

  • Thread starter Thread starter Abohy
  • Start date Start date
A

Abohy

Guest
I have a datagriedview contains many rows of numbers.

And i have a datatable with one column contains numbers.

I want to highlight datagrideview rows that not in datatable rows .. I compare between just one column

Here is my code:

DataTable SeatNum = new DataTable()
SeatNum = ......
try
{
foreach (DataGridViewRow row in dataGridView2.Rows)
{
if (row.IsNewRow) { return; }
foreach (DataRow dtrow in SeatNum.Rows)
{
if (dtrow[0].ToString() != (row.Cells[0].Value.ToString()))

{
row.Cells[0].Style.BackColor = Color.Red;
MessageBox.Show("Not Exist" + row.Cells[0].Value.ToString() + "\r\n" + dtrow[0].ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
break;
}
else
{
row.Cells[0].Style.BackColor = row.DefaultCellStyle.BackColor;
MessageBox.Show( "Exist" + row.Cells[0].Value.ToString() + "\r\n" + dtrow[0].ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
break;
} }
}
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
This code just highlight the rows that not match to the first row in datatable


Thank you in advance.

Continue reading...
 
Back
Top