Passing List View items to a report viewer in windows form using vb.net

  • Thread starter Thread starter Amr_Aly
  • Start date Start date
A

Amr_Aly

Guest
Hi Everyone

I have a list view that contained more than one row i want to pass it to a report viewer but i face a problem

if i have one row it appears in report viewer (repeated four times) and if i have more than one row the last row only appears

(repeated four times) like this picture

1358710.pngHere is My code , in case of using for loop or not ,i get the same result.....

'Print()
Dim con As New OleDbConnection(cs)
Dim da As New OleDbDataAdapter()
Dim ds As New DataSet
Dim cmd As New OleDbCommand("SELECT * FROM BillSold")
cmd.CommandType = CommandType.Text
cmd.Connection = con
da.SelectCommand = cmd
'ds.Clear()
da.Fill(ds, "DataSet1")

Dim rds As New ReportDataSource("DataSet1", ds.Tables(0))

SearchForm15.ReportViewer1.LocalReport.ReportPath = Path.Combine(Application.StartupPath, "E:\KMAStock\KMAStock\Report1.rdlc")
SearchForm15.ReportViewer1.LocalReport.DataSources.Clear()
SearchForm15.ReportViewer1.LocalReport.DataSources.Add(rds)

Dim invoiceno As New ReportParameter("InvoiceNoParam", Me.txtInvoiceNo.Text)
Dim solddate As New ReportParameter("SoldDateParam", Me.dtpTransactionDate.Text)
Dim customername As New ReportParameter("CustomerNameParam", Me.cmbcustomername.Text)


'Dim i As Integer
'For Each ii In ListView1.Items(0).SubItems

For i = 0 To ListView1.Items.Count - 1
If ListView1.Items.Count <> 0 Then

'For i = 0 To ListView1.Items.Count - 1
With ListView1.Items.Item(i)
Dim productcode As New ReportParameter("ProductCodeParam", Val(.SubItems(1).Text))
Dim productparam As New ReportParameter("ProductParam", (.SubItems(2).Text))
Dim sprice As New ReportParameter("SellPriceParam", Val(.SubItems(5).Text))
Dim soldcartons As New ReportParameter("SoldCartonsParam", Val(.SubItems(6).Text))
Dim soldpackets As New ReportParameter("SoldPacketsParam", Val(.SubItems(7).Text))
Dim totalamount As New ReportParameter("TotalAmountParam", Val(.SubItems(8).Text))

SearchForm15.ReportViewer1.LocalReport.SetParameters(New ReportParameter() {productcode})
SearchForm15.ReportViewer1.LocalReport.SetParameters(productparam)
SearchForm15.ReportViewer1.LocalReport.SetParameters(sprice)
SearchForm15.ReportViewer1.LocalReport.SetParameters(soldpackets)
SearchForm15.ReportViewer1.LocalReport.SetParameters(soldcartons)
SearchForm15.ReportViewer1.LocalReport.SetParameters(totalamount)
End With
End If
Next

'Next
'For i = 0 To ListView1.Items.Count - 1
' Dim productcode As New ReportParameter("ProductCodeParam", Val(Me.ListView1.Items(i).SubItems(1).Text))
' Dim productparam As New ReportParameter("ProductParam", (Me.ListView1.Items(i).SubItems(2).Text))
' Dim sprice As New ReportParameter("SellPriceParam", Val(Me.ListView1.Items(i).SubItems(5).Text))
' Dim soldcartons As New ReportParameter("SoldCartonsParam", Val(Me.ListView1.Items(i).SubItems(6).Text))
' Dim soldpackets As New ReportParameter("SoldPacketsParam", Val(Me.ListView1.Items(i).SubItems(7).Text))
' Dim totalamount As New ReportParameter("TotalAmountParam", Val(Me.ListView1.Items(i).SubItems(8).Text))
' 'If cbxPatName.Text = String.Empty Then
' ' MsgBox("ادخل اسم العميل", MsgBoxStyle.Information, "اسم العميل مطلوب")
' ' Exit Sub
' 'ElseIf cbxPatName.Text <> String.Empty Then
' ' TabControl1.SelectedTab = Me.TabPage6

' SearchForm15.ReportViewer1.LocalReport.SetParameters(productcode)
' SearchForm15.ReportViewer1.LocalReport.SetParameters(productparam)
' SearchForm15.ReportViewer1.LocalReport.SetParameters(sprice)
' SearchForm15.ReportViewer1.LocalReport.SetParameters(soldpackets)
' SearchForm15.ReportViewer1.LocalReport.SetParameters(soldcartons)
' SearchForm15.ReportViewer1.LocalReport.SetParameters(totalamount)
' 'Exit For
'Next

'For i = 0 To ListView1.Items.Count - 1
' Dim productcode As New ReportParameter("ProductCodeParam", Val(Me.ListView1.Items(i).SubItems(1).Text))
' Dim productparam As New ReportParameter("ProductParam", (Me.ListView1.Items(i).SubItems(2).Text))
' Dim sprice As New ReportParameter("SellPriceParam", Val(Me.ListView1.Items(i).SubItems(5).Text))
' Dim soldcartons As New ReportParameter("SoldCartonsParam", Val(Me.ListView1.Items(i).SubItems(6).Text))
' Dim soldpackets As New ReportParameter("SoldPacketsParam", Val(Me.ListView1.Items(i).SubItems(7).Text))
' Dim totalamount As New ReportParameter("TotalAmountParam", Val(Me.ListView1.Items(i).SubItems(8).Text))
' 'If cbxPatName.Text = String.Empty Then
' ' MsgBox("ادخل اسم العميل", MsgBoxStyle.Information, "اسم العميل مطلوب")
' ' Exit Sub
' 'ElseIf cbxPatName.Text <> String.Empty Then
' ' TabControl1.SelectedTab = Me.TabPage6
' SearchForm15.ReportViewer1.LocalReport.SetParameters(productcode)
' SearchForm15.ReportViewer1.LocalReport.SetParameters(productparam)
' SearchForm15.ReportViewer1.LocalReport.SetParameters(sprice)
' SearchForm15.ReportViewer1.LocalReport.SetParameters(soldpackets)
' SearchForm15.ReportViewer1.LocalReport.SetParameters(soldcartons)
' SearchForm15.ReportViewer1.LocalReport.SetParameters(totalamount)
'Next
'End If
SearchForm15.ReportViewer1.LocalReport.SetParameters(invoiceno)
SearchForm15.ReportViewer1.LocalReport.SetParameters(solddate)
SearchForm15.ReportViewer1.LocalReport.SetParameters(customername)

'SearchForm15.ReportViewer1.SaveReport()
SearchForm15.ReportViewer1.Refresh()
SearchForm15.ReportViewer1.RefreshReport()
SearchForm15.ReportViewer1.LocalReport.Refresh()


SearchForm15.TabControl1.SelectedTab = SearchForm15.TabPage4
SearchForm15.ShowDialog()

Any suggestions will be appreciated

Thanks in advance..........


Regards From Amr_Aly

Continue reading...
 
Back
Top