循环通过两个gridviews vb

时间:2015-12-21 14:00:34

标签: asp.net vb.net gridview

我正在寻找比较两个aspxgridviews的结果。

例如:
第一次网格视图
1
2
3

第二次Gridview
1
2
3
4
5

我希望列表框中的输出为4 5。

到目前为止,这是我的代码:

For k As Integer = 0 To DataGridView.VisibleRowCount - 1

    For j As Integer = 0 To ExcelGridView.VisibleRowCount - 1

        If DataGridView.GetRowValues(k, "Column1").Equals(ExcelGridView.GetRowValues(j, "F2")) Then

        Else

            ResultMemo.Text = DataGridView.GetRowValues(k, "Column1")

            ListBox1.Items.Add(ResultMemo.Text)

            Exit For

        End If

    Next j

Next k

1 个答案:

答案 0 :(得分:0)

DataGridView = 2nd Gridview 1 2 3 4 5
ExcelGridView = 1st Gridview 1 2 3

按照你的风格会是这样的:

For k As Integer = 0 To DataGridView.VisibleRowCount - 1 
    dim isNotFound = true
    For j As Integer = 0 To ExcelGridView.VisibleRowCount - 1 
        If DataGridView.GetRowValues(k, "Column1")=(ExcelGridView.GetRowValues(j, "F2") Then 
            isNotFound = false
            Exit For 
        End If 
    Next For
    If isNotFound then
        dim forAdd = DataGridView.GetRowValues(k, "Column1") 
        ResultMemo.Text = forAdd 
        ListBox1.Items.Add(forAdd) 
    End If
Next For