-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.vb
78 lines (68 loc) · 3.1 KB
/
Form1.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
Imports DevExpress.XtraBars.Ribbon
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraReports.ReportGeneration
Imports DevExpress.XtraReports.UI
Imports System.Data
Namespace ConvertGridToReportExample
Partial Public Class Form1
Inherits RibbonForm
Public Sub New()
InitializeComponent()
' This line of code is generated by Data Source Configuration Wizard
' Fill the SqlDataSource asynchronously
sqlDataSource1.FillAsync()
End Sub
Private Sub btnShowPreview_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnShowPreview.ItemClick
Dim report As XtraReport1 = CreateReportFromGrid()
Dim printTool As New ReportPrintTool(report)
printTool.ShowPreviewDialog(Me.GetActiveLookAndFeel())
End Sub
Private Sub btnShowReportDesigner_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnShowReportDesigner.ItemClick
Dim report As XtraReport1 = CreateReportFromGrid()
Dim designTool As New ReportDesignTool(report)
designTool.ShowDesignerDialog(Me.GetActiveLookAndFeel())
End Sub
Private Function CreateReportFromGrid() As XtraReport1
Dim dSource As Object
Dim dMember As String
If chkOnlyExpRecords.Checked Then
dSource = FillDatasetFromGrid()
dMember = Nothing
Else
dSource = sqlDataSource1
dMember = sqlDataSource1.Queries(0).Name
End If
Dim report As New XtraReport1(dSource, dMember, gridView)
Return report
End Function
Private Function FillDatasetFromGrid() As DataTable
Dim rowHandle As Integer
Dim dTable As New DataTable()
For Each c As GridColumn In gridView.Columns
dTable.Columns.Add(c.FieldName, c.ColumnType)
Next c
For r As Integer = 0 To gridView.RowCount - 1
rowHandle = gridView.GetVisibleRowHandle(r)
If Not gridView.IsGroupRow(rowHandle) Then
Dim rowValues(dTable.Columns.Count - 1) As Object
For c As Integer = 0 To dTable.Columns.Count - 1
rowValues(c) = gridView.GetRowCellValue(rowHandle, dTable.Columns(c).ColumnName)
Next c
dTable.Rows.Add(rowValues)
End If
Next r
Return dTable
End Function
Private Sub btnReportGeneratorPreview_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnReportGeneratorPreview.ItemClick
Dim options As New ReportGenerationOptions() With {.PrintVerticalLines = DevExpress.Utils.DefaultBoolean.True, .PrintHorizontalLines = DevExpress.Utils.DefaultBoolean.True}
Dim report As XtraReport = ReportGenerator.GenerateReport(gridView, options)
Dim printTool As New ReportPrintTool(report)
printTool.ShowPreviewDialog(Me.GetActiveLookAndFeel())
End Sub
Private Sub btnReportGeneratorDesigner_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnReportGeneratorDesigner.ItemClick
Dim report As XtraReport = ReportGenerator.GenerateReport(gridView)
Dim designTool As New ReportDesignTool(report)
designTool.ShowDesignerDialog(Me.GetActiveLookAndFeel())
End Sub
End Class
End Namespace