Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report view question 2

Status
Not open for further replies.

apex1x

IS-IT--Management
Aug 14, 2002
396
0
0
US
Hi
I am trying to do a series of reports using the standard reportview object in vb.net 2005. The current one would be more of an invoice, where data from multiple tables are put together to get the report. One thing is I would need the invoice number generated on a different form to be passed to the report as a filter. I am really getting stuck on this and can't find too many resources to help out so I'm wondering if anyone could point me in the right direction or suggest a perhaps better way to do it.

Thanks. And let me know if you'd like anything elaborated on.
 
I can think of a couple of ways to do this.

Option 1:
You build an object that will store the data for an individual invoice. You would then search your data sources with a data layer, and build an instance of this object. In the event that you needed to make more than one invoice, you would build them and add them to a collection (generic list, array list, array....etc).

If you set your report datasource to be this type of object instead of a direct data source. Then you simply would pass in the information and it would display properly. If you were to pass in a List of these objects it would repeat the report for each object, if you simply pass in one, it would generate only one.

Option 2:
You put a parameter on your report definition. Choose Report, Parameters, and add "InvoiceNum" for example. Within you code before pulling up the report viewer.
Code:
Dim params(0) As Microsoft.Reporting.WinForms.ReportParameter
params(0) = New Microsoft.Reporting.WinForms.ReportParameter("InvoiceNum", 10001)
Me.ReportViewer1.LocalReport.SetParameters(params)

Hope that is clear at least starts you in the right direction.

 
Ok, thanks for the tips. I'll see if I can start to figure those out. Would anyone suggest some good sites on working with such things? Thanks.
 
Just to follow up, that "10001" would be used as the filtering criteria, no? When I add at design time the parameter, what sort of entries would I add, assuming that I'm taking the value out of a text box on form1? Would that affect the runtime code you gave me? Thanks
 
Yes 10001 would be your filtering criteria. I am not sure what you are asking about entries to add. You could take the value out of a textbox on a form, you would just pass in that value instead of 10001.

Another way you could do this, would be to create an object like "Invoice" and set properties for all the values you want to display on a report (InvoiceNum, CustomerName, etc.....). At this point you would pass this datasource to the report, which would then display it.

I could possibly give a more detailed example later if you need.
 
I'd love a more detailed example, as I'm quite new to this. Thanks :)
 
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
 
Ok, I'll see if I can digest that :)
When I add a field to the report header, an error comes up saying you cannot have a field in a report header. Does this mean I cannot have the invoice number, for example, in the header? How would I go about doing this, assuming I have a new datatable with the selected Invoice/Customer information that needs to be linked to the report? Thanks.
 
As far as I can tell, all data processing is done in the Detail section, so you would have to add the fields there. Header and footer sections must have static (or Parameter) variables.

If adding the invoice number to the top right of the detail section (for example) doesnt fit your needs, I am not sure how, or if you could get database values into the header section.
 
What I've tried doing was have a textbox in the header link to a value in the detail, using the =reportitems!textbox107.Value, for example, where textbox107 has the invoice number. The only problem is when the report is multiple pages, only the last page will show those values. Anybody know why that is, how I could fix it or possibly have another solution? Thanks.
 
I should also add that referencing a textbox from a table in the body section works fine but only if I keep that particular textbox visible. Is there a way around this?
 
I have never referenced another text box on a form, you could pass in a parameter
Code:
Dim params(0) As Microsoft.Reporting.WinForms.ReportParameter
params(0) = New Microsoft.Reporting.WinForms.ReportParameter("InvoiceNum", 10001)
Me.ReportViewer1.LocalReport.SetParameters(params)


another way might be to reference the field value, not the header text value, like this (though I havent tested this)
So if text box 127 is showing the invoice number, and the data field from your datasource is INV_NUM, it would be something like this...
Code:
=Fields!INV_NUM.Value
 
I more or less have all the data showing up the way I want, except for the page header. The page header should have the invoice number, invoice date, etc, but since apparantly you can't reference fields in a header, there must be another way to have that info be printed off in the header on every page.

One thing I tried was I added a couple columns on the detail's table and put the invoice date/number in the header portion of that table and then referenced those texboxes in the page header. The only problem is that I do not want those extra columns showing up and once I set them to not visible, the data no longer shows up in the header texboxes.

I can't seem to think of a more logical way to go about this but I'm open to any suggestions, Thanks.
 
Ok, I was able to get the appropriate info in the page header by just hiding the columns (changing them to white). The only thing now is that I'm looking to have the report forced to print the detail section all the way up until the page footer. Is this possible? Right now it just generates some white space.
 
I am not sure I follow you, but if you have white space under the fields you are reporting, it will put that in the report as well, if you shrink the detail section to be flush with a field, it should remove the extra white space, if there is not enough detail, however, it will of course show white space

does that even make sense?

 
Yes, sorry for not being more specific...

What I have is the detail section flush, however the chances are the details will end before a new page is filled up. Also, the page footer is always applied in the same spot at the bottom. So what I basically want is lines continued from the details table, drawn down to meet the page footer. I suppose I'm looking for something like a formula in the details section to keep printing off blank lines until it hits the end of the page (meets the page footer). Is that a bit more clear?

 
Blank lines as in a table row with borders, so there is something displayed instead of whitespace?

if that is the case, I am not sure how you would do that off the top of my head - when I get a moment I will try and see if I can think of a way.....
 
Yeh, so it would look something like a typical invoice:
Code:
                       <-this is the header 
----------------
|   Details1   |
|   Details2   |       <-repeated details
|   DetailsX   |
----------------
|              |        <--- these are the lines I want
|              |      
----------------
|    Footer    |
----------------
 
Any ideas on this? Even abstract ones I'd consider ;)
 
i thought that the page would by default fill with whitespace, but if you want to have visible rows, the only thing that comes to mind would be a little crazy, but here goes.

Get a count of the number of rows that can be displayed on the page, find out how many rows will be displayed on the final page, and add blank rows to accomodate.

I am not 100% sure how you would even do this, or if it would even work, but I think you would have to include these bogus rows when pulling the data...

sorry I am not more help =)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top