Grid控件合并

fangchunliang 2010-10-24 12:55:22
1 A 100BL ...............
1)
2)
.
.
2 M 200BL ..............
3 K 500BL .................
4 G 1000BL ............
5 B 1500BL ..............

如何在Grid控件根据其子项有合并其主项呀?这样就不用重复相同部分的主项了.各位高手,请问如何有VB如何写代码?
是否先查询出有多少条记录是子项,再去填充合并是相同部分呢,可否详细告知,先谢谢了!
...全文
73 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
cqq_chen 2010-10-24
所有的表中有一个相同的字段名,比例:单据修改日期
然后所有查询结果显示之间判定单据修改日期的位置,再后显示时主表只做一次,位置到单据修改日期,子表每条记录都显示...

思路大概是这样,再说就说不明白了.

If Not AdoEoF(sc) Then Exit Sub
' SayStatus "正在处理相关数据,请稍候……", 5
scnum = 0
For i = 0 To sc.Fields.count - 1

If sc.Fields(i).Name = "FZdDate" Then
scnum = i + 1
Exit For
End If

Next i


sc.MoveLast
sc.MoveFirst
menu.Pb.Max = sc.RecordCount + 1
menu.Pb.Value = 0
menu.Pb.Min = 0
With vadisp
.MaxRows = 0
.MaxRows = sc.RecordCount + 1
j = 1
k = 2
str1 = sc.Fields(0)
Do While Not sc.EOF
DoEvents
If FQuitSear Then
MsgBox "中断查询结果显示,现在所显示的只是部分查询结果!", vbExclamation + vbOKOnly, "龙奕提示"
Exit Sub
End If
'Debug.Print sc.Fields(0) & " " & str1 & " " & Str(j)
If str1 = sc.Fields(0) And k = 1 Then
For i = scnum To sc.Fields.count - 1
.Col = i + 1
.Row = j
.Text = sc.Fields(i) & ""
.Lock = True

.ForeColor = FontColor
d.Open "select * from TPrintSetEntry where F_num=" & F_Num & " and FName" & Lang & "='" & sc.Fields(i).Name & "'", Conn

.ColWidth(.Col) = d.Fields("FWidth") * 567
If d.Fields("FType") = "int" Then
.CellType = CellTypeInteger
ElseIf d.Fields("FType") = "dec" Then
.CellType = CellTypeFloat
.TypeFloatDecimalPlaces = d.Fields("FDecWidth")
ElseIf d.Fields("FType") = "bool" Then
.CellType = CellTypeCheckBox
.TypeHAlign = TypeHAlignCenter
If sc.Fields(i) Then
.Value = True
Else
.Value = False
End If
End If
d.Close
Next i
'k = 2
Else
For i = 0 To sc.Fields.count - 1
.Col = i + 1
.Row = j
'.ForeColor = RGB(255, 0, 0)
.Text = sc.Fields(i) & ""
.ForeColor = FontColor
d.Open "select * from TPrintSetEntry where F_num=" & F_Num & " and FName" & Lang & "='" & sc.Fields(i).Name & "'", Conn

.ColWidth(.Col) = d.Fields("FWidth") * 567
If d.Fields("FType") = "int" Then
.CellType = CellTypeInteger
ElseIf d.Fields("FType") = "dec" Then
.CellType = CellTypeFloat
.TypeFloatDecimalPlaces = d.Fields("FDecWidth")
ElseIf d.Fields("FType") = "bool" Then
.CellType = CellTypeCheckBox
.TypeHAlign = TypeHAlignCenter
If Left(sc.Fields(i), 1) = "已" Or sc.Fields(i) Then
.Value = True
Else
.Value = False
End If
End If
d.Close
Next i
k = 1
End If
'End If
str1 = sc.Fields(0)
sc.MoveNext
j = j + 1
menu.Pb.Value = j '''
Loop
.Col = 1
.Row = j
.Text = "合计"
' Debug.Print F_Num
For i = 0 To sc.Fields.count - 1
.Col = i + 1
d.Open "select * from TPrintSetEntry where F_num=" & F_Num & " and FName" & Lang & "='" & sc.Fields(i).Name & "'", Conn

If d.Fields("FTj") Then
.SetRefStyle RefStyleDefault
If d.Fields("FType") = "int" Then
.CellType = CellTypeInteger
ElseIf d.Fields("FType") = "dec" Then
.CellType = CellTypeFloat
.TypeFloatDecimalPlaces = d.Fields("FDecWidth")
End If
.Formula = "sum(" & ColToAbc(i + 1) & "1:" & ColToAbc(i + 1) & Trim(Str(.MaxRows - 1)) & ")" '"Sum(R[-1]C:R[-" & Trim(Str(j)) & "]C)"
End If
d.Close
Next i
If F_Num = 7253 Then
.Col = 8
.CellType = CellTypeFloat
.TypeFloatDecimalPlaces = 4
.SetRefStyle RefStyleR1C1
.Formula = "RC[9]/RC[8]"
End If
End With


sc.MoveFirst
回复
相关推荐
发帖

1188

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2010-10-24 12:55
社区公告
暂无公告