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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print Report 1

Status
Not open for further replies.

tag141

Technical User
Oct 4, 2003
119
AU
Sorry to ask such a question but I cannot find the answer anywhere. I have added a report (Report1.rdlc) to my application. All I want to do is be able to press a button and have it print. My problem is that nowhere can I find anything to tell me how to do it. Even MSDN is pretty vague. In VB6 it was fairly easy but VB.net 2005 it seems pretty complicated. Is this right?

Can anyone start me off in the right direction or point me to an easy to understand tutorial? I don't want to be shown the code as it won't teach me a thing.

TIA.
 
If you have added the ReportViewer control to your form and attached the .RDLC file to it, you should have all the ptint options available automatically.

Have a look here for one of the best tutorials I've seen on using the ReportViewer:



Hope this helps.

[vampire][bat]
 
I notice that you have posted another question today.

Did you find the link I posted above useful?

[vampire][bat]
 
Sorry Earthandfire, didn't realise you had posted again. I read the website and to be honest I'm none the wiser on report printing. Rather than spend too much time trying to figure it out, I moved on through the development and will come back to printing when I'm nearer the end.

I may build the app in VB6 and be done with it as the more I get into it, the more I want it to do and the harder it becomes.!!
 
When you are ready, if you repost, I'll have a look at it in more detail.


Hope this helps.

[vampire][bat]
 
OK earthandfire you're up...

I have managed to get the report viewer working using the site you mentioned. It loads all my data as I suppose it should but...I want only one record showing on the report. I am currently using treeview to populate my textboxes and it works rather nicely. However, I did read that treeview can't use datasets automatically but this has to be hand coded. (Again I followed a tutorial.)

1)Can I populate a report directly using treeview?
2)How can I filter my data so I get the report I want?
3)Can I populate a report from textboxes on a form?

Help/tutorials would be gratefully accepted.
 
earthandfire,

here's how I sorted it. Maybe of use to other people who are trying to create a report for a single record using treeview.

I created a table called report and created a dataset and table adapter from that table. The table holds one record only. That it used to populate the table on the report. In the treeview after select sub, I included an update command. That simply updates the report table with the data in the textboxes. That in turn is sent to the report.

Code:
    Private Sub trvContacts_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles trvContacts.AfterSelect
        Dim data_row As DataRow
        Dim data_table As DataTable
        Dim i As Integer


        ' Do nothing if we haven't loaded the data yet.
        If m_CurrencyManager Is Nothing Then Exit Sub

        ' Do nothing if this node has no Tag 
        ' value or Tag isn't a DataRow object.
        If e.Node.Tag Is Nothing Then Exit Sub

        ' Display the corresponding record.
        data_table = dsContacts.Tables(0)
        data_row = e.Node.Tag
        For i = 0 To m_CurrencyManager.Count - 1
            If data_row Is m_CurrencyManager.List(i).Row Then
                m_CurrencyManager.Position = i
                Exit For
            End If
        Next i

        Try

            conContacts.Open()

            ContactsDataSet.report.Rows(0).Item("sname") = txtLastName.Text
            ContactsDataSet.report.Rows(0).Item("fname") = txtFirstName.Text
            ContactsDataSet.report.Rows(0).Item("zip") = txtZip.Text
            'strWriteRecord = True

            ' Update the database.
            ReportTableAdapter.Update(ContactsDataSet.report)
            Me.ReportViewer1.RefreshReport()
            conContacts.Close()

        End Try
 
    End Sub

and it works !!! If anyone can better the code please feel free I would be very interested in seeing better ways to do it. Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top