Vb.net 将关联的DataGridView行返回给它';s对应的数据表行

Vb.net 将关联的DataGridView行返回给它';s对应的数据表行,vb.net,Vb.net,重新格式化这个问题,因为似乎没有人理解它。我有一个名为dtCSV的数据表。我正在dtCSV中搜索一个特定的值,我能够找到我需要的行(我不需要这部分的帮助)。dtCSV还绑定到datagridview。(这就是我需要帮助的地方)我如何在datagridview控件中获取我通过搜索找到的行并找到它对应的行,以便高亮显示整行?谢谢 Function GetDebitorsString(ByVal Name As String, ByVal RowName As String) As String

重新格式化这个问题,因为似乎没有人理解它。我有一个名为dtCSV的数据表。我正在dtCSV中搜索一个特定的值,我能够找到我需要的行(我不需要这部分的帮助)。dtCSV还绑定到datagridview。(这就是我需要帮助的地方)我如何在datagridview控件中获取我通过搜索找到的行并找到它对应的行,以便高亮显示整行?谢谢

Function GetDebitorsString(ByVal Name As String, ByVal RowName As String) As String
    Dim dt As New DataTable

    If System.IO.File.Exists("data\debitors\debitors.xml") Then
        dt.ReadXml("data\debitors\debitors.xml")
    Else
        MsgBox("File data\debitors\debitors.xml was not found.", MsgBoxStyle.Information, "Warning")
        Return String.Empty
    End If


    Dim FoundRow() As DataRow = dt.Select("Name='" & Name & "'")
    If FoundRow IsNot Nothing Then
        Return FoundRow(0).Item(RowName).ToString
    Else
        Return String.Empty
    End If
End Function

Private Sub btnScan_Click(sender As Object, e As EventArgs) Handles btnScan.Click
    'looks through all the bills in the CSV and see's if they match with the inputted bills. If they match the cleared date is inputted into the cleared column and the row is turned green in the csv dgv

    For Each row In dt.Rows 'loop through each of the bills listed looking for a matching bank statement with the same amount paid
        If GetDebitorsString(row("Name").ToString, "Search") IsNot String.Empty Then 'find the search string for the debitor
            Dim FoundRow() As DataRow = dtCSV.Select("Description Like '*" & GetDebitorsString(row("Name").ToString, "Search") & "*'") 'try to see if any bank statements match the search string
            If FoundRow.Count >= 0 Then
                'item was found 
                If row("Amount Paid").ToString IsNot String.Empty Then 'ignore bills with no amounts typed in 
                    If Convert.ToDouble(row("Amount Paid")) = Convert.ToDouble(FoundRow(0).Item("Debit")) Then 'if the amount listed in the bill matches the amount in the bank statement 
                        row("Cleared") = FoundRow(0).Item("Date").ToString 'set the date it cleared in the cleared cell

                    End If

                End If

            End If
        End If
    Next

如果您知道DGV中名称的搜索键和列号,只需使用for循环即可

例如:

    Dim key = "Andrew"
    Dim col_Name = 5
    For Each r As DataGridViewRow In dgvCSV.Rows
        If r.Cells(col_Name).Value = key Then
            Return r.Index
        End If
    Next

不需要循环。当然不是在DataGridView上。找到搜索项时,只需使用其中一个事件高亮显示该行。您需要为目标设置一个表单级变量。我们确实理解了第一个版本