Click here to Skip to main content
15,911,896 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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:

VB
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
Posted

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.
 
Share this answer
 
VB
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

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900