做报表时经常要对数据的显示进行调整,而且老板的要求经常会很古怪。先前一直用C# 做,现在用下vb,很久没有接触,都不怎么熟悉了
下面代码因为赶时间,有空稍微注释一下
1

Private Sub CellSpan()Sub CellSpan()2
Dim supplier As String3
Dim cost As Decimal4
Dim totalCost As Decimal5
Dim jobNum As Integer6
Dim rowIndex As Integer7
Dim i As Integer8

9
If dgSupplierJob.Items.Count > 0 Then10
supplier = dgSupplierJob.Items(0).Cells(0).Text11
dgSupplierJob.Items(0).Cells(0).RowSpan = 112
dgSupplierJob.Items(0).Cells(1).RowSpan = 113
dgSupplierJob.Items(0).Cells(2).RowSpan = 114

15
rowIndex = 016
jobNum = 117
totalCost = CDec(dgSupplierJob.Items(0).Cells(2).Text)18

19
For i = 1 To dgSupplierJob.Items.Count - 120
If dgSupplierJob.Items(i).Cells(0).Text = supplier Then21
totalCost = totalCost + CDec(dgSupplierJob.Items(i).Cells(2).Text)22
jobNum = jobNum + 123

24
dgSupplierJob.Items(i).Cells(0).Visible = False25
dgSupplierJob.Items(i).Cells(1).Visible = False26
dgSupplierJob.Items(i).Cells(2).Visible = False27

28
dgSupplierJob.Items(rowIndex).Cells(0).RowSpan = dgSupplierJob.Items(rowIndex).Cells(0).RowSpan + 129
dgSupplierJob.Items(rowIndex).Cells(1).RowSpan = dgSupplierJob.Items(rowIndex).Cells(1).RowSpan + 130
dgSupplierJob.Items(rowIndex).Cells(2).RowSpan = dgSupplierJob.Items(rowIndex).Cells(2).RowSpan + 131

32
Else33
supplier = dgSupplierJob.Items(i).Cells(0).Text34

35
dgSupplierJob.Items(i - jobNum).Cells(1).Text = jobNum.ToString()36
dgSupplierJob.Items(i - jobNum).Cells(2).Text = totalCost.ToString()37

38
totalCost = CDec(dgSupplierJob.Items(i).Cells(2).Text)39

40
jobNum = 141

42
dgSupplierJob.Items(i).Cells(0).RowSpan = 143
dgSupplierJob.Items(i).Cells(1).RowSpan = 144
dgSupplierJob.Items(i).Cells(2).RowSpan = 145

46
rowIndex = i47

48
End If49
Next50
End If51
End Sub
浙公网安备 33010602011771号