VB 如何使用Datareport打印MSHFlexGrid中多条选中的记录

xxjzzit 2012-10-25 05:03:19
问题:如何使用Datareport打印MSHFlexGrid中多条选中的记录

MSHFlexGrid中的记录是通过查询得到的(连接有数据库),但是目标用户,要求对单击选中其中的几条记录进行打印,这个功能如

何实现的??

目前,自己可以实现单击选中某一天进行打印,或是打印MSHFlexGrid中的全部记录,但在打印“选中多条记录(连续

或不连续都有可能)”上遇到了困难,特次求助了?多谢!!!
...全文
262 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
king06 2012-10-26
  • 打赏
  • 举报
回复
MSFlexGrid1_MouseDown MSFlexGrid1_MouseUp事件中标记一下选中的行,打印的时候再根据这个标记来判断是否打印。以前我做了一个是用rowdata属性来弄的,翻出来了给你参考一下吧
Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim i As Long, j As Long
If MSFlexGrid1.MouseRow = 0 Then Exit Sub

If Button = 1 Then
If Shift = 2 Then
With MSFlexGrid1
For j = 1 To .Cols - 1
.Col = j
If .CellBackColor = &H8000000D Then
.CellForeColor = &H80000008
.CellBackColor = &H80000005
.RowData(.Row) = 0
Else
.CellForeColor = &H8000000E
.CellBackColor = &H8000000D
.RowData(.Row) = 1
End If
Next
End With
ElseIf Shift = 1 Then
With MSFlexGrid1
If .Row <= .RowSel Then
For i = .Row To .RowSel
.RowData(i) = 1
Next
Else
For i = .Row To .RowSel Step -1
.RowData(i) = 1
Next
End If
End With
End If
End If
End Sub
Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim i As Long, j As Long
Dim lngRow As Long, lngRowSel As Long
If MSFlexGrid1.MouseRow = 0 Then Exit Sub

DoEvents
If Shift = 0 Then
With MSFlexGrid1
.Redraw = False
lngRow = .Row
lngRowSel = .RowSel
For i = 1 To .Rows - 1
If i <> lngRowSel And .RowData(i) = 1 Then
.Row = i
For j = 1 To .Cols - 1
.Col = j
.CellForeColor = &H80000008
.CellBackColor = &H80000005
Next
.RowData(i) = 0
End If
Next

.Row = lngRow

If .Row <= lngRowSel Then
For i = lngRow To lngRowSel
.Row = i
.RowData(i) = 1

For j = 1 To .Cols - 1
.Col = j
.CellForeColor = &H8000000E
.CellBackColor = &H8000000D
Next
Next
Else
For i = lngRow To lngRowSel Step -1
.Row = i
.RowData(i) = 1

For j = 1 To .Cols - 1
.Col = j
.CellForeColor = &H8000000E
.CellBackColor = &H8000000D
Next
Next
End If

.Redraw = True
End With
End If
End Sub
c_cyd2008 2012-10-25
  • 打赏
  • 举报
回复
先生成一个RecordSet,和你报表的DataSource有相同结构,然后将选中的记录添加到生成的RecordSet中,最后 Set 报表.DataSource=RecordSet

7,765

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧