how can i change the value of data in crystal report base on the selected item in listview?
i am using mysql and visual studio 2012

Recommended Answers

All 11 Replies

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

where would i put that?

Post the part of your code you are using the generate the reports

We can't help if we can't see the code. =)

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

tnx i will try these and come back to you

not working :(

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)

yup a database value

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.