0

我正在遍历 vb net 中的 datagridview 中的列并将值传递给文本框。我需要能够过滤掉 Cell(4) 中的电子邮件,这样就没有任何单个客户的重复电子邮件。

我不知道如何使用数据集来做到这一点。

EmailTableAdapter.Fill(Me.EmailDataset.Email)

  Dim r As String = String.Empty
        For i As Integer = 0 To Me.EmailDataGridView.RowCount - 1
            r = r & EmailDataGridView.Rows(i).Cells(7).Value.ToString & "  -  " & EmailDataGridView.Rows(i).Cells(4).Value.ToString & vbNewLine
        Next
        TextBox2.Text = (r)
4

1 回答 1

0

在 Cells(4) 中过滤掉具有重复值的行的一种方法是遍历网格行,使用 Cells(4) 值作为键将项目填充到字典中,然后遍历字典以构建您的“r”细绳。这样的解决方案看起来像这样:

EmailTableAdapter.Fill(Me.EmailDataset.Email)

Dim EmailDict As New Dictionary(Of String, String)
For i As Integer = 0 To Me.EmailDataGridView.RowCount - 1
    If Not EmailDict.ContainsKey(EmailDataGridView.Rows(i).Cells(4).Value.ToString) Then
        EmailDict.Add(EmailDataGridView.Rows(i).Cells(4).Value.ToString, EmailDataGridView.Rows(i).Cells(7).Value.ToString)
    End If
Next

Dim EmailPair As KeyValuePair(Of String, String)
Dim r As String = String.Empty
For Each EmailPair In EmailDict
    r &= EmailPair.Value & "  -  " & EmailPair.Key & vbNewLine
Next

TextBox2.Text = (r)
于 2013-03-09T22:49:02.153 回答