循环通过两个数据网格视图 [英] Loop through two data grid view
本文介绍了循环通过两个数据网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
i有两个数据网格视图,在第一个数据网格视图中我有3列
ID收到的主题
和第二个数据网格视图8列
ID主题收到日期用户等等
i希望用第二个数据网格视图的主题检查第一个数据网格视图中的主题行,并在标记列中说匹配或不匹配在第二个数据网格视图中。
有人请帮我这个双循环
什么我试过了:
Hello,
i have two data grid views and in the first data grid view i have 3 column
ID SUBJECT RECEIVED
and second data grid view 8 columns
ID subject received date user etc
i want to check the subject line in the first data grid view with second data grid view's subject and say "matching" or " not matching in the "mark" column in second data grid view.
someone please help me with this double loop
What I have tried:
'Dim rowindex As String
'Dim found As Boolean = False
''
'Dim i As Integer = 1
'For Each row As DataGridViewRow In LiveinboxDataGridView.Rows
' For Each rowww As DataGridViewRow In ElapsedDataGridView.Rows
' Dim str As String
' str = TextBox1.Text
' Dim xxx As String = rowww.Cells.Item(10).Value
' MsgBox(xxx)
' MsgBox(row.Cells.Item(7).Value)
' If row.Cells.Item(7).Value = xxx Then
' ' rowindex = row.Index.ToString()
' found = True
' ' Dim actie As String = rowww.Cells("Received").Value.ToString()
' MsgBox("Found")
' ' Exit For
' 'Exit For
' End If
' Next
'Next
'If Not found Then
' MsgBox("Item not found")
'End If
推荐答案
首先简化:创建一个String列表,并使用第一个DataGridView中的Subject值填充它 - 这是一个简单的For Each循环。
如果有,可以使用Linq Contains方法检查列表是否包含每个值: Enumerable.Contains(TSource)方法(IEnumerable(TSource),TSource)(System.Linq) [ ^ ] - 它返回一个布尔值,您可以使用它直接设置Mark列的值。
那样,你不需要嵌套循环,你处理N1 + N2循环,而不是N1 * N2
Start by simplifying that: Create a List Of String and populate it with the Subject values from the first DataGridView - that's a trivial For Each loop.
When you have that, you can use the Linq Contains method to check if the list contains each value: Enumerable.Contains(TSource) Method (IEnumerable(TSource), TSource) (System.Linq)[^] - it returns a Boolean which you can use to set the value of your Mark column directly.
That way, you don't need to nest the loops, and you process N1 + N2 loops, instead of N1 * N2
这篇关于循环通过两个数据网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文