ok, here is a VERY basic example.
you have the following items:
1. Invoice Object (InvoiceObject.vb)
2. Report Definition File
3. Form to Get Data and show report (Form1.vb)
4. Form with Report Viewer (Form2.vb)
I will try to base this example on you original request.
1. Invoice Object - a snippet...
Code:
Public Class InvoiceObject
Public Property InvoiceNumber() as integer
...
Public Property CustomerName() as string
....
End Class
2. Report Definition File - this report will has a datasource that has been set to the Invoice Object class. This is accomplished by going to the DataSources tab by the solution explorer. Choose add new datasource, choose object, select Invoice Object. Once you have created the datasource you are now able to refer to fields from that datasource on your report (in this case public properties). Based on the above definition you would have InvoiceNumber, and CustomerName as items that could be displayed on the report.
3. Form to Get Data - you are going to want to get your data in whatever way you see fit, directly from SQL, or another source, or using a Mult-Tier solution. This example is not going to go into great detail but provide you with an idea of what needs to be done.
Code:
'perhaps this is called from a button click and the invoice number is in a text field on the form as you suggested
Public Function BuildReportData(InvoiceNum as integer) as invoiceObject
'Search data source for matching data
'with returned data build the data for the report
Dim Invoice as New InvoiceObject()
Invoice.InvoiceNumber = InvoiceNum
Invoice.CustomerName = 'get matching data from the data you have recieved in your previous query.
'Return a Object with the data in which we need to report
return Invoice
end Function
4. Form with Report Viewer - the important thing to remember here is if you are opening this form from a previous form, and the data is build on that previous form you must pass that data to this form - so it is able to provide it to the report. You can do this through a property or change the New Function to accept it as a parameter.
When you add a report viewer to the form and select a form a databinding item is displayed below, I usually rename it to something more convienent. Like "ReportDS"
Finally you need to use this item in order to get the data into the report.
Code:
Private _InvoiceData as InvoiceObject ' local variable for invoice data
Public Sub New(ByVal ReportData as InvoiceObject)
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
' Set the local data to the provided data
_InvoiceData = ReportData
'Set the DataSource Object to the data object, since the report is defined to accept this type of object, it will then report properly on the fields that have been selected in the report definition - furthermore, if you wanted to report on more than one entry (this example is only one entry) you could build a generic typed list of this object, and the detail area of the report would repeat for each invoice object
Me.ReportDS.DataSource = _InvoiceData
End Sub
hope that helps
-Dave