如何使用VB.NET在没有数据源的水晶报表中显示datagridview中的所有行 [英] How to display all rows in datagridview in crystal report without no datasource using VB.NET
问题描述
我更新的编程我需要一些帮助我想在Crystal报表中显示Datagridview中的所有行我的DatagridView没有DataSource我只是添加所有值手动到它之后我插入所有值我要点击一个按钮发送所有这些使用Visual Studio 2015的Cythal报告我只是创建新项目并放入Datagridview1和CrystalReportViewer1这是我的代码下的按钮移动到水晶
Iam newer in programming i need some help I Want To Show All Rows In Datagridview in Crystal report In Case My DatagridView Has No DataSource I just add All value Manual To it After I Insert All Value I want To Click A Button To send All This Rows To Cyrstal Report iam using Visual Studio 2015 I just create New project and put Datagridview1 and CrystalReportViewer1 And this Is My Code Under Button Move To crystal
Dim crystal As New CrystalReport1
crystal.SetDataSource(DataGridView1.DataSource)
CrystalReportViewer1.ReportSource = crystal
CrystalReportViewer1.Refresh()
and when i click the button i got this the report has no table Error Picture
<a href="https://i.stack.imgur.com/N9blQ.jpg"></a>
what to do
我尝试过:
i尝试了这段代码我写的帮助我
What I have tried:
i tried this code i wrote it Help Me
推荐答案
如果是 DataGridView [ ^ ]组件未与某些数据源绑定,a DataSource属性 [ ^ ]返回Nothing
。
因此,您需要为水晶报告创建数据源。请参阅:
In case when a DataGridView[^] component is not bind with some data source, a DataSource property[^] returnsNothing
.
So, you need to create a data source for crystal report. See:
Dim dgv As DataGridView = Me.DataGridView
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(dgv.Columns.Cast(Of DataGridViewColumn)().Select(Function(x) New DataColumn(x.Name)).ToArray())
dt = dgv.Rows.Cast(Of DataGridViewRow)() _
.Select(Function(x) _
dt.LoadDataRow(New Object() _
{ _
x.Cells(0).Value, _
x.Cells(1).Value, _
x.Cells(2).Value _
}, False)) _
.CopyToDataTable()
Dim crystal As New CrystalReport1
crystal.SetDataSource(dt)
CrystalReportViewer1.ReportSource = crystal
CrystalReportViewer1.Refresh()
您可以通过使用简单的来实现相同的...下一步
循环 DataGridView $ c中的列和行$ c>。
祝你好运!
You can achieve the same by using simple for ... next
loop by columns and rows in DataGridView
.
Good luck!
这篇关于如何使用VB.NET在没有数据源的水晶报表中显示datagridview中的所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!