Does your report cycle through the listview's items?

If so, just execute the report on the listview's selcted items.

Example:

For Each itm as ListViewItem in ListView1.SelectedItems
    'Do Work
Next

i dont have a code in my crystal report

i am only using Select * from command in crystal report

If you have a unique value in the selected listviewitem (I normally make it the first value) you can do this:

"SELECT * FROM table WHERE column='" & listview1.SelctedItems(0).Text & "'"
'This is assuming that the first column contains the unique value.

'If not, you will have to reference the location (0th based) like so
"SELECT * FROM table WHERE column='" & listview1.SelectedItems(0).Subitem(1).Text & "'"
'This will reference the second column, just set the Subitem index to n-1 of the column

Ok. Let's recap.

You have a report generated from a select statement.

You want this report to retreive only the data selected from the listview.

Does the listview contain data that has been inserted into the database, or is it just values the user inserted into it? (without committing to the database)

Try this:

Create a new (hidden) listview.

Store the data into the listview.

Fire the report off against the hidden listview.

Example:

'Declare the listview
Dim lvwHidden As New ListView

With lvwHidden

    'Set the columns/settings here.

End With

For Each itm as ListViewItem in ListView1.SelectedItems
    'Send each item selected to the hidden listview
    lvwHidden.Items.Add(itm)
Next

'Fire the report off against the hidden listview

how to bypass this w/o providing a full path of crystal report

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

        Dim cryRpt As New ReportDocument
        cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt")

        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition
        Dim crParameterValues As New ParameterValues
        Dim crParameterDiscreteValue As New ParameterDiscreteValue

        crParameterDiscreteValue.Value = TextBox1.Text
->        crParameterFieldDefinitions =  -
->          cryRpt.DataDefinition.ParameterFields
->        crParameterFieldDefinition =  _
->          crParameterFieldDefinitions.Item("Customername")
        crParameterValues = crParameterFieldDefinition.CurrentValues

        crParameterValues.Clear()
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

        CrystalReportViewer1.ReportSource = cryRpt
        CrystalReportViewer1.Refresh()
    End Sub
End Class

it gives me an error on this area if i dont provide the full path

Edited 4 Years Ago by Shodow

This article has been dead for over six months. Start a new discussion instead.