从列datagridview vb.net中删除重复数据
我环顾四周,没有找到答案:/ 截图: 我希望该条目只显示一次,而不是停留在那里(“to”列),基本上删除重复项。这是我的更新代码从列datagridview vb.net中删除重复数据,vb.net,datagridview,datagridviewcolumn,Vb.net,Datagridview,Datagridviewcolumn,我环顾四周,没有找到答案:/ 截图: 我希望该条目只显示一次,而不是停留在那里(“to”列),基本上删除重复项。这是我的更新代码 Private Sub datagridview1Update() 'Remove rows if there are too many If DataGridView1.Rows.Count > 9 Then DataGridView1.Rows.RemoveAt(0) End If DataGridView
Private Sub datagridview1Update()
'Remove rows if there are too many
If DataGridView1.Rows.Count > 9 Then
DataGridView1.Rows.RemoveAt(0)
End If
DataGridView1.Rows.Add()
DataGridView1.Rows(DataGridView1.Rows.Count - 2).Cells(0).Value = ipfrom.ToString 'From Column, size at 125
DataGridView1.Rows(DataGridView1.Rows.Count - 2).Cells(1).Value = ipto.ToString 'To Column, size at 125
DataGridView1.Rows(DataGridView1.Rows.Count - 2).Cells(2).Value = destinationport.ToString
DataGridView1.Rows(DataGridView1.Rows.Count - 2).Cells(3).Value = sourceport.ToString
End Sub
首先,您应该循环查看DataGridView1的行,以查看是否已经存在与新数据匹配的条目。如果未找到匹配项,则添加新行。此外,您应该只从行数中减去一行,以保持正确的顺序
Private Sub datagridview1Update()
Dim bolFoundMatch As Boolean = False
Dim intCursor As Integer = 0
Do Until bolFoundMatch OrElse intCursor = DataGridView1.Rows.Count
If DataGridView1.Rows(intCursor).Cells(1).Value = ipto.ToString() Then
bolFoundMatch = True
End If
intCursor += 1
Loop
If Not bolFoundMatch Then
'Remove rows if there are too many
If DataGridView1.Rows.Count > 9 Then
DataGridView1.Rows.RemoveAt(0)
End If
DataGridView1.Rows.Add()
DataGridView1.Rows(DataGridView1.Rows.Count - 1).Cells(0).Value = ipfrom.ToString 'From Column, size at 125
DataGridView1.Rows(DataGridView1.Rows.Count - 1).Cells(1).Value = ipto.ToString 'To Column, size at 125
DataGridView1.Rows(DataGridView1.Rows.Count - 1).Cells(2).Value = destinationport.ToString
DataGridView1.Rows(DataGridView1.Rows.Count - 1).Cells(3).Value = sourceport.ToString
End If
End Sub
数据来自哪里?你想要的是一个“锯齿状”的显示-一些没有“To”的行吗?@puropoix它来自我的网络适配器,它是一个数据包捕获程序,它捕获了大量不同的“To”,但它只是一直在超快速滚动我想限制到一个让我再给你一个屏幕截图:我希望它每相同的“To”只显示一次ipif数据在数据源中,您可以检查是否存在重复数据,而不向其中添加重复数据。@Proputix数据源是否具有访问权限?这是从我的网络适配器进行的实时捕获和填充。不,这与访问无关。
DataGridView
的数据源只是一个实现IList
接口的对象。这可能是从Access数据库或其他数据库或其他类型列表(例如POCO数组)填充的DataTable
。我将其设置为1,但出于某种原因,如果我喜欢,它会跳过行。见: