本文介绍了在VB.NET中对多个datagridviews中的重复值求和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 我在tabcontrol中的表单上有多个datagridviews,每个都包含以下列:ref,Bestand zu KHK(HW) ),Bestand Menge和Bestandsart。 问题是ref包含重复值,我想要做的是删除所有重复的值并将相应的Bestand zu KHK(HW),Bestand Menge合并为一个。 我的尝试: Dim i = t1 - 1 Do直到i = t2 Dim j = 0 Do until j = datagridviews(i).RowCount 如果不是datagridviews(i).Rows(j).Cells(ref ).Value.Equals(0)然后 Dim s1 Dim s2 s1 = datagridviews(i).Rows(j).Cells(Bestand zu KHK(HW) ))。值 s2 = datagridviews(i).Rows(j).Cells(Bestand Menge)。Value For t = j + 1 To datagridviews(i).RowCount - 1 如果datagridviews(i).Rows(j).Cells(ref)。Value.Equals(datagridviews(i).Rows(t).Cells(ref) .Value)和datagridviews(i).Rows(j).Cells(Bestandsart)。Value.Equals(datagridviews(i).Rows(t).Cells(Bestandsart)。Value)然后 s1 = s1 + datagridviews(i).Rows(t).Cells(Bestand zu KHK(HW)。) s2 = s2 + datagridviews(i).Rows(t).Cells(Bestand Menge) ).Value datagridviews(i).Rows(t).Cells(ref)。Value = 0 datagridviews(i).Rows(t).Cells(Bestandsart) ).Value = 0 datagridviews(i).Rows(t).Cells(Bestand Menge)。Value = 0 datagridviews(i).Rows(t).Cells(Bestand zu KHK (HW))。值= 0 结束如果下一个 datagridviews(i).Rows(j).Cells(Bestand zu KHK(HW))。值= s1 da tagridviews(i).Rows(j).Cells(Bestand Menge)。Value = s2 j = j + 1 ElseIf datagridviews(i).Rows(j).Cells(ref)。Value.Equals(0)然后j = j + 1 结束如果 循环 BackgroundWorker1.ReportProgress((i - (t1 - 1)+ 1)/(t2 - t1 + 1)* 100)i = i + 1 循环 一旦我点击按钮执行代码,我就不会收到错误但它返回部分总和意味着我仍然看到一些重复的值,我必须再按一次才能完成这项工作。 目前有21个datagridviews,每个包含大约1100排。 有人可以帮忙或指向正确的方向。 提前感谢。解决方案 Hello everyone,I have multiple datagridviews on my form in a tabcontrol, each one contain the following columns: "ref", "Bestand zu KHK (HW)", "Bestand Menge" and "Bestandsart".the problem is that "ref" contains repeated values, what I want to do is remove all the duplicated values and sum the corresponding "Bestand zu KHK (HW)", "Bestand Menge" into one.What I have tried:Dim i = t1 - 1 Do Until i = t2 Dim j = 0 Do Until j = datagridviews(i).RowCount If Not datagridviews(i).Rows(j).Cells("ref").Value.Equals(0) Then Dim s1 Dim s2 s1 = datagridviews(i).Rows(j).Cells("Bestand zu KHK (HW)").Value s2 = datagridviews(i).Rows(j).Cells("Bestand Menge").Value For t = j + 1 To datagridviews(i).RowCount - 1 If datagridviews(i).Rows(j).Cells("ref").Value.Equals(datagridviews(i).Rows(t).Cells("ref").Value) And datagridviews(i).Rows(j).Cells("Bestandsart").Value.Equals(datagridviews(i).Rows(t).Cells("Bestandsart").Value) Then s1 = s1 + datagridviews(i).Rows(t).Cells("Bestand zu KHK (HW)").Value s2 = s2 + datagridviews(i).Rows(t).Cells("Bestand Menge").Value datagridviews(i).Rows(t).Cells("ref").Value = 0 datagridviews(i).Rows(t).Cells("Bestandsart").Value = 0 datagridviews(i).Rows(t).Cells("Bestand Menge").Value = 0 datagridviews(i).Rows(t).Cells("Bestand zu KHK (HW)").Value = 0 End If Next datagridviews(i).Rows(j).Cells("Bestand zu KHK (HW)").Value = s1 datagridviews(i).Rows(j).Cells("Bestand Menge").Value = s2 j = j + 1 ElseIf datagridviews(i).Rows(j).Cells("ref").Value.Equals(0) Then j = j + 1 End If Loop BackgroundWorker1.ReportProgress((i - (t1 - 1) + 1) / (t2 - t1 + 1) * 100) i = i + 1 Looponce I click a button to execute the code, I don't get an error but it returns partial sums meaning that I still see some repeated values and I have to press one more time to do the job.currently there is 21 datagridviews and each contains around 1100 row.can someone please help or point in the right direction.thanks in advance. 解决方案 这篇关于在VB.NET中对多个datagridviews中的重复值求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-30 04:30