逐个单元地比较2个datagridviews [英] Comparing 2 datagridviews cell by cell

查看:65
本文介绍了逐个单元地比较2个datagridviews的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我正在做一个项目,我需要将datagridview1的第一个单元格中的值与datagridview2中的所有值进行比较。我没有做对,循环使我感到困惑。有人请帮帮我..!

谢谢。

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.

推荐答案

试试这个代码



Try this code

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
            }



谢谢&注意

Sham:)


Thanks & Regard
Sham :)


这篇关于逐个单元地比较2个datagridviews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆