Hello World !, I have a small detail, from a button I am comparing two columns of two datagridviews. What I want to get is: From the DataDridView1
to get all the data that does not exist in DataGridView2
. What I really did is compare the data and those that are the same paint the row of DataGridView1
, until there all good.
My problem is in the same DataGridView1
I have a checkbox in the first column ( Cells(0)
) and I have to activate the checkboxes for the data that do not match. According to me if the CheckBox is deactivated and when NOT, they activate it but that logic does not work for me because it leaves all of them activated.
Annex code to see where I'm doing wrong.
private void btnAdicionales_Click(System.Object sender, System.EventArgs e)
{
int intContador = 0;
for (var i = 0; i <= this.DataGridView1.Rows.Count - 1; i++)
{
for (var j = 0; j <= this.DataGridView2.Rows.Count - 1; j++)
{
if (Trim(System.Convert.ToString(DataGridView1.Rows(i).Cells(1).Value)) == Trim(System.Convert.ToString(DataGridView2.Rows(j).Cells(0).Value)))
{
DataGridView1.Rows(i).Cells(1).Style.BackColor = Color.Coral;
DataGridView1.Rows(i).Cells(2).Style.BackColor = Color.Coral;
DataGridView1.Rows(i).Cells(3).Style.BackColor = Color.Coral;
DataGridView1.Rows(i).Cells(4).Style.BackColor = Color.Coral;
DataGridView1.Rows(i).Cells(5).Style.BackColor = Color.Coral;
DataGridView1.Rows(i).Cells(7).Style.BackColor = Color.Coral;
intContador += 1;
DataGridView1.Rows(i).Cells(0).Value = false;
}
else
DataGridView1.Rows(i).Cells(0).Value = true;
}
}
int intDif = 0;
intDif = intContador - System.Convert.ToInt32(DataGridView1.Rows.Count);
ToolStripStatusLabel3.Text = "Adicionales: " + System.Convert.ToString(intDif);
}
I appreciate the suggestions you can give me.