仅在水晶报表中打印选定的datagridview行 [英] Print only selected datagridview rows in a crystal report
问题描述
我在水晶报告中遇到麻烦。我只希望在我的报告中显示dgv中的选定行。当我选择一行时,它正在工作,但当我选择多行时,它不起作用。请在我的代码中指导我。这是我的代码:
Hi,
i am having a trouble in printing in crystal report. i want only the selected row in dgv will show in my report. it is working when i select a single row, but when i select multiple row it doesn''t work. please guide me in my code. here is my code:
Me.TblEmployeeTableAdapter.Fill(Me.MyDataSet.tblEmployee)
Me.crp_Employee.SetDataSource(Me.MyDataSet)
Me.CrystalReportViewer1.SelectionFormula = "{tblEmployee.Emp_No} = '" & frmEmployee.dg.SelectedCells(0).Value & "'"
Me.CrystalReportViewer1.ReportSource = Me.crp_Employee
Me.CrystalReportViewer1.RefreshReport()
任何帮助将不胜感激。 :)谢谢
any help would be much appreciated. :) thanks
推荐答案
难道你不能再向SelectionForumla添加另一个条件,比如
Couldn''t you just add another condition to the SelectionForumla, like
{tblEmployee.Emp_No} = ''someValue'' OR {tblEmployee.Emp_No} = ''someOtherValue'' OR ...
并继续按要求添加。
and keep adding them as required.
Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click
Dim i As New Integer
Dim myparams As New ParameterFields
Dim myparam As New ParameterField
Dim rpt2 As New CrystalReport2()
i = 0
myparam.ParameterFieldName = "ids"
For i = 0 To Me.DataGridView1.SelectedRows.Count - 1
Dim myDiscreteValue As New ParameterDiscreteValue()
myDiscreteValue.Value = System.Convert.ToInt32(Me.DataGridView1.SelectedRows(i).Cells(0).Value)
myparam.CurrentValues.Add(myDiscreteValue)
' Add param object to params collection
myparams.Add(myparam)
Next i
rpt2.SetDataSource(DataSet31)
printmulti.CrystalReportViewer1.ReportSource = rpt2
printmulti.CrystalReportViewer1.ParameterFieldInfo = myparams
printmulti.CrystalReportViewer1.Refresh()
printmulti.Show()
End Sub
将此项添加到记录选择公式{Table_1.id} = {?ids}并选择(左ctrl + lmousebutton)多行,按代码按钮(button31_click),您可以打印多个记录。
add this to the record selection formula {Table_1.id} = {?ids} and select (left ctrl + lmousebutton) multiple rows, press the code button (button31_click) and you can print multiple records.
这篇关于仅在水晶报表中打印选定的datagridview行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!