Vb.net 在DataGridView中检查重复项
我有一个If和一个嵌套If,它拒绝包含值大于0的列的行。嵌套的If应该检查double并将我需要的重复值相加,但它不是。我不确定我错过了什么Vb.net 在DataGridView中检查重复项,vb.net,datagridview,Vb.net,Datagridview,我有一个If和一个嵌套If,它拒绝包含值大于0的列的行。嵌套的If应该检查double并将我需要的重复值相加,但它不是。我不确定我错过了什么 Dim rowValue As String Dim cellValue As String() If System.IO.File.Exists("shortlist.csv") Then Using streamReader As System.IO.StreamReader = New StreamReader(
Dim rowValue As String
Dim cellValue As String()
If System.IO.File.Exists("shortlist.csv") Then
Using streamReader As System.IO.StreamReader = New StreamReader("shortlist.csv")
'Defines columns
rowValue = streamReader.ReadLine()
cellValue = rowValue.Split(",")
With dgv.Columns
.Add(cellValue(0).ToString, cellValue(0).ToString)
.Add(cellValue(3).ToString, cellValue(3).ToString)
.Add(cellValue(5).ToString, cellValue(5).ToString)
.Add(cellValue(6).ToString, cellValue(6).ToString)
.Add(cellValue(8).ToString, cellValue(8).ToString)
End With
' Reading content
While streamReader.Peek() <> -1
Dim cnt As Integer = 0
rowValue = streamReader.ReadLine()
cellValue = rowValue.Split(",")
If (cellValue(6) > 0) Then
'comparing works. need to tinnker with loop.
If (cellValue(0).ToString <> dgv.Rows(cnt).Cells("Phone Number").Value) Then
dgv.Rows.Add(cellValue(0).ToString, cellValue(3).ToString, cellValue(5).ToString, cellValue(6).ToString, cellValue(8).ToString)
Else
dgv.Rows(cnt).Cells(3).Value = (cellValue(6) + Integer.Parse(dgv.Rows(cnt).Cells(3).Value))
dgv.Rows(cnt).Cells(4).Value = (cellValue(8) + Integer.Parse(dgv.Rows(cnt).Cells(4).Value))
cnt += 1
End If
End If
End While
End Using
Else
MsgBox("No File is Selected")
End If
我正在使用的.CSV文件有几列,第一列是电话号码。当我阅读每一行的电话号码时,我遇到了一个重复的电话号码,我想将两列中的值添加到它们唯一的行中。能否请您提供更多的代码cellValue代码来自哪里?更清楚地解释一下你想要实现什么?另外,您没有解释代码中的预期内容,也没有解释实际发生的情况。cellValue是一个字符串数组,它包含我试图排序的.CSV文件中的当前行。您是否考虑过.CellsPhone Number.Value将返回一个对象?因此,为了将其与ToString值进行比较,您应该更喜欢.CellsPhone Number.value.ToString。