blah blah blah is here! blah blah » Close

up1down
link

Is it possible to search a datagridview column to match entries against another gridview?

Example i have 2 datagridviews, in the first gridview column [1] i have an ID number on the second datagrid column [1] there's also an ID number in the cells, now - i want to search datagridview2 column [1] and if any ID numbers match datagridview1 column [1] then change cell back color to green.

last answered one year ago

1 answers

link

This code should do it:

for(int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
DataGridViewRow row1 = dataGridView1.Rows[i];

for (int j = 0; j < dataGridView2.Rows.Count - 1; j++)
{
DataGridViewRow row2 = dataGridView2.Rows[j];
if (row1.Cells[1].Value.ToString() == row2.Cells[1].Value.ToString())
{
row2.Cells[1].Style.BackColor = Color.Green;
}
}
}

WOW - vulpes that's fantastic, i'm still trying to get my head round datagrids and what's possible, that's just what i was looking for thanks, works a treat.

Feedback