本文介绍了如何比较两个datagridview行单元格的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何比较两个datagridview值?我正在尝试检查Datagridview2中是否存在Datagridview1主题代码

How can i compare two datagridview values ? I'm trying to check if Datagridview1 subjectcode is Exist in Datagridview2

当用户单击按钮时会发生.所选行将添加到datagridview2列表

It will happen when user click a button. Selected row will be added in datagridview2 list

if datagridview1 subcode  = datagridview2 subcode then
         datagridview1.row color  = gray. 

Datagridview1 (这是一个主题列表)

Datagridview1 ( This is a subject list )

Datagridview2

推荐答案

您可以从DataGridView创建一个子代码列表,并以此方式进行检查.

You could create a list of subcode from the DataGridView and check it that way.

Dim subCodeList as new List(Of String)

For i as Integer = 0 To datagridview1.Rows.Count - 1
    subCodeList.add(datagridview1.Rows(i).Cells("subCode").Value.toString())
Next

' Then in your second DataGridView
For i as Integer = 0 To datagridview2.Rows.Count - 1
    If subCodeList.Contains(datagridview2.rows(i).cells("subCode").value.tostring()) THEN
       ' Do something if it's found.
    End if

Next

也许有一种更简单的方法可以做到这一点,但这可能会让您入门.

There might be an easier way to do this but this might get you started.

这篇关于如何比较两个datagridview行单元格的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 01:15