Click here to Skip to main content
16,018,264 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
I am doing a project where I need to compare the value in the first cell of datagridview1 with all the values in datagridview2. I am not getting it right, looping has confused me. Someone please help me out..!
thank you.
Posted
Comments
Neema Derakhshan 28-Aug-13 23:57pm    
what is your code?
do you have to compare gridviews?
why don't you compare data?
kishore sharma 29-Aug-13 1:10am    
You need to compare only first cell value or like this keep doing with all cells?

1 solution

Try this code

C#
bool Status = false;
foreach (DataGridViewRow row in DataGridView2.Rows)
            {
                for (int i = 0; i < DataGridView2.Columns.Count; i++)
                {
                    if (DataGridView1["ColumnIndex", "RowIndex"].Value == DataGridView2[i, row.Index].Value)
                    {
                        Status = true;
                        break;
                    }
                }
            }
            //And then check Available Status
            if (Status == true)
            {
                //Value Available in DataGridView2
            }
            else
            {
                 //Value not Available
            }

Thanks & Regard
Sham :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900