C# 如何在datagridview vb.net中删除包含原始数据的重复数据
如何删除datagridview中的重复数据和原始数据?我尝试了不同的代码,但我只删除了重复的代码C# 如何在datagridview vb.net中删除包含原始数据的重复数据,c#,vb.net,duplicates,C#,Vb.net,Duplicates,如何删除datagridview中的重复数据和原始数据?我尝试了不同的代码,但我只删除了重复的代码 Dim i As Integer = 0 While i < numberOfRows For ii As Integer = (numberOfRows) To (i + 1) Step -1 If dtg3.Rows(i).Cells(0).Value.ToString() = dtg3.Rows(ii).Cells(0).Value.ToSt
Dim i As Integer = 0
While i < numberOfRows
For ii As Integer = (numberOfRows) To (i + 1) Step -1
If dtg3.Rows(i).Cells(0).Value.ToString() =
dtg3.Rows(ii).Cells(0).Value.ToString() And
dtg3.Rows(i).Cells(2).Value.ToString() =
dtg3.Rows(ii).Cells(2).Value.ToString() And
dtg3.Rows(i).Cells(3).Value.ToString() =
dtg3.Rows(ii).Cells(3).Value.ToString() And
dtg3.Rows(i).Cells(8).Value.ToString() =
dtg3.Rows(ii).Cells(8).Value.ToString() Then
dtg3.Rows.Remove(dtg3.Rows(ii))
numberOfRows -= 1
End If
Next
i += 1
End While
Dim i作为整数=0
当我在数排的时候
对于ii,作为整数=(numberOfRows)到(i+1)步骤-1
如果dtg3.Rows(i).Cells(0).Value.ToString()=
dtg3.Rows(ii).Cells(0).Value.ToString()和
dtg3.Rows(i).Cells(2.Value.ToString()=
dtg3.Rows(ii).Cells(2).Value.ToString()和
dtg3.Rows(i).Cells(3.Value.ToString()=
dtg3.Rows(ii).Cells(3).Value.ToString()和
dtg3.Rows(i).Cells(8.Value.ToString()=
dtg3.Rows(ii).Cells(8).Value.ToString()然后
dtg3.行。移除(dtg3.行(ii))
行数-=1
如果结束
下一个
i+=1
结束时
我想要的是,从我的datagridview中删除重复数据和原始数据,希望有人在这里帮助我。好了
For Each row As DataGridViewRow In DataGridView1.Rows
For Each nextrow As DataGridViewRow In DataGridView1.Rows
If row.Index <> nextrow.Index Then
If row.Cells(0).Value = nextrow.Cells(0).Value Then
MsgBox("Duplicate on col 0, index = " & row.Index.ToString)
End If
If row.Cells(2).Value = nextrow.Cells(2).Value Then
MsgBox("Duplicate on col 2, index = " & row.Index.ToString)
End If
If row.Cells(3).Value = nextrow.Cells(3).Value Then
MsgBox("Duplicate on col 3, index = " & row.Index.ToString)
End If
If row.Cells(8).Value = nextrow.Cells(8).Value Then
MsgBox("Duplicate on col 8, index = " & row.Index.ToString)
End If
End If
Next
Next
将每行作为DataGridView1.Rows中的DataGridViewRow进行
对于每个nextrow,在DataGridView1.Rows中显示为DataGridViewRow
如果是row.Index nextrow.Index,则
如果row.Cells(0).Value=nextrow.Cells(0).Value,则
MsgBox(“第0列重复,索引=“&row.index.ToString”)
如果结束
如果row.Cells(2).Value=nextrow.Cells(2).Value,则
MsgBox(“第2列重复,索引=“&row.index.ToString”)
如果结束
如果row.Cells(3).Value=nextrow.Cells(3).Value,则
MsgBox(“在第3列重复,index=“&row.index.ToString”)
如果结束
如果row.Cells(8).Value=nextrow.Cells(8).Value,则
MsgBox(“第8列重复,索引=“&row.index.ToString”)
如果结束
如果结束
下一个
下一个
这还将检查所有列是否重复,不仅仅是它下面的行,就像在您的示例中一样,您在递增i和递增ii,因此您总是同时只检查2行,而不是将1行与所有其他行进行比较。对于dtg3中作为DataGridViewRow的每一行。行
For Each row As DataGridViewRow In dtg3.Rows
For Each nextrow As DataGridViewRow In dtg3.Rows
If row.Index <> nextrow.Index Then
If row.Cells(0).Value = nextrow.Cells(0).Value AndAlso
row.Cells(2).Value = nextrow.Cells(2).Value AndAlso row.Cells(3).Value =
nextrow.Cells(3).Value AndAlso row.Cells(8).Value = nextrow.Cells(8).Value Then
dtg3.Rows.Remove(row)
dtg3.Rows.Remove(nextrow)
End If
End If
Next
Next
对于每个nextrow作为dtg3.Rows中的DataGridViewRow
如果是row.Index nextrow.Index,则
如果row.Cells(0).Value=nextrow.Cells(0).Value和also
row.Cells(2).Value=nextrow.Cells(2).Value和其他row.Cells(3).Value=
nextrow.Cells(3).Value和行.Cells(8).Value=nextrow.Cells(8).Value然后
dtg3.行.删除(行)
dtg3.行.删除(下一步)
如果结束
如果结束
下一个
下一个
vb.net=
,
,不是
C#首先用“AndAlso”替换“all”和“AndAlso”为什么你用while和for循环而不是2个for循环,你在哪里定义了“numberOfRows”?兄弟,你是个救生员,非常感谢你的努力,我做了你的建议,现在就可以了。没问题,伙计,很高兴我能帮上忙我在原来的帖子上投了赞成票,因为我错投了你的反对票:/