I have two datatables, each with 1 column:
dtTempCM dtOldTempCM
In both tables, the only column name is Column1
I also have 2 datagridviews in the form, each of which is bound to a datatable:
dgvCurrentCM.DataSource = dtTempCM; dgvOldCM.DataSource = dtOldTempCM;
How can I compare each row and select it in one (or both) datagridviews objects if they do not match? So far I have this:
foreach (DataRow row1 in dtTempCM.Rows) { foreach (DataRow row2 in dtOldTempCM.Rows) { var array1 = row1.ItemArray; var array2 = row2.ItemArray; if (array1.SequenceEqual(array2)) {
Any ideas? Thanks!
EDIT: I tried this too, but it changes the color of each cell as it compares each row in dgvOldCM with one row in dgvCurrentCM:
foreach (DataGridViewRow row1 in dgvCurrentCM.Rows) { foreach (DataGridViewRow row2 in dgvOldCM.Rows) { if (row1.Cells[0].Value != row2.Cells[0].Value) { row1.DefaultCellStyle.ForeColor = Color.Red; row2.DefaultCellStyle.ForeColor = Color.Red; } } }
source share