Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2006

Tip: Looking for answers? Try searching our database.

print form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John - 13 Jul 2006 12:09 GMT
If I want to set up my Vb 2005 windows app so users can print some data from
a dataset, what options do I have to do this?  It seems I should be able to
find a whole section on printing data but I haven't been able to find my way
around in "Help" to well.
Linda Liu [MSFT] - 14 Jul 2006 03:49 GMT
Hi John,

Thank you for posting.

If you want to print some data from a dataset, I think you have two options
to do this.

1. Using crystal report

  a. Create a crystal report (.rpt file) in your project.
  b. Bind the dataset to the report.
  c. If you want to preview the report before printing, add a
CrystalReportViewer control on a form and bind the report to the
CrystalReportViewer.
  d. Make use of the CrystalReportViewer by clicking the print button on
its toolbar to print the report. You may also call the PrintToPrinter
method of the report to print it.

For more information on how to create a crystal report, you could refer to
the following link:
http://msdn2.microsoft.com/en-us/library/ms227360(d=ide).aspx

2. Using report definition (.rdlc) file

  a. Create a report definition file in your project.
  b. Bind the dataset to the report.
  c. Add a ReportViewer control on a form and bind the report to the
ReportViewer.
  d. Make use of the ReportViewer by clicking the print button on its
toolbar to print the report.

For more information on how to create a report definition file, you could
refer to the link below:
http://msdn2.microsoft.com/en-us/library/ms252067(d=ide).aspx

Hope this helps.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

============================================================================
=============================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

With newsgroups, MSDN subscribers enjoy unlimited, free support as opposed
to the limited number of phone-based technical support incidents. Complex
issues or server-down situations are not recommended for the newsgroups.
Issues of this nature are best handled working with a Microsoft Support
Engineer using one of your phone-based incidents.

============================================================================
=============================================
This posting is provided "AS IS" with no warranties, and confers no rights.
John - 14 Jul 2006 15:14 GMT
I have tried the Crystal reports option following the instructions on the
link you sent.  The wizard is very easy and straightforward yet, my report
has nothing in it??  What could I be doing wrong?  The table definately has
data in it since it dispays fine on the main form.  but when I call my
report form, it's a niclety setup form with nothing in it.

> Hi John,
>
[quoted text clipped - 55 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
Linda Liu [MSFT] - 17 Jul 2006 12:18 GMT
Hi John,

Thank you for your quick response.

To display data of the DataSet in the crystal report, you should connect
the DataSet to the report in the report designer.

The following is a walkthrough.

1. Double-click the crystal report in Solution Explorer to display it in
the report designer.

2. If Field Explorer doesn't appear, make the Toggle Field View ToolItem
pressed down in the Crystal Reports-Main Toolbar.

3. In Field Explorer, right-click the Database Fields node and select
Database Experts command.

4. In the Database Expert window, unfold the nodes "Project Data" and
"ADO.NET DataSets" , select  DataTables from the DataSet and press the add
button.

5. Press OK button to close the  Database Expert window.

6. In Field Explorer, you will see the DataTables you selected just now
have been added under the node Database Fields.

7. Drag the fields of the DataTables from Field Explorer and drop onto the
details section of the report one by one.

When the program is running, the data in the DataSet will be displayed in
the crystal report. Of course, you should fill the data into the DataSet
before the crystal report is shown.

Hope this helps.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support
John - 19 Jul 2006 15:08 GMT
It appears my problem may be because I fill the Dataset in one form which
calls another form that is going to show the report.  What is the proper way
to deal with this situation?  I tried making it Public just as a trial but
that didn't seem to fix it.

> Hi John,
>
[quoted text clipped - 36 lines]
> Linda Liu
> Microsoft Online Community Support
Linda Liu [MSFT] - 20 Jul 2006 05:20 GMT
Hi John,

Thank you for your response.

If you fill the DataSet in one form(e.g Form1) and call another form(e.g
Form2) to show the report, you should set the DataSource of the report in
Form2 with the DataSet you have filled in Form1before Form2 is shown.

I recommend you to write a public method in Form2 to set the DataSource of
the report. Remember to call this method in Form1 before you show the Form2.

Here is a sample code for you. The sample requires that you have placed a
CrystalReportViewer control named crystalReportViewer1 on Form2.

public partial class Form2 : Form
   {
       public Form2()
       {
           InitializeComponent();
           // CrystalReport1 is the report I have created in the project.
You should replace it with the name of your own CrystalReport.
           CrystalReport1 report = new CrystalReport1();
           this.crystalReportViewer1.ReportSource = report;
       }
       
        // The DataSet1 is the name of the DataSet I have created in the
project. You should replace it with the name of your own DataSet.
       public void SetDataSourceToReport(DataSet1 dataset)
       {
         
((CrystalReport1)this.crystalReportViewer1.ReportSource).SetDataSource(datas
et);
       }      
   }

public partial class Form1 : Form
   {
       private void button1_Click(object sender, EventArgs e)
       {
           Form2 frm = new Form2();
           frm.SetDataSourceToReport(this.dataset);
           frm.Show();
       }
   }

Hope this helps.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support
John - 21 Jul 2006 11:21 GMT
I'm using VB so this is a little difficult for me to look at but I will try
to decipher it.  If you could put an example in vb I'd appreciate it though.

> Hi John,
>
[quoted text clipped - 48 lines]
> Linda Liu
> Microsoft Online Community Support
Linda Liu [MSFT] - 24 Jul 2006 08:52 GMT
Hi John,

Thank you for your response.

Here is the example in VB.NET.

Public Class Form2

   Public Sub New()

       ' This call is required by the Windows Form Designer.
       InitializeComponent()

       ' Add any initialization after the InitializeComponent() call.
       Dim report As New CrystalReport1
       Me.crystalReportViewer1.ReportSource = report
   End Sub

   Public Sub SetDataSourceToReport(ByRef dataset As DataSet)
       CType(Me.CrystalReportViewer1.ReportSource,
CrystalReport1).SetDataSource(dataset)
   End Sub
End Class

public class Form1 : Form
   
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

       Dim frm As Form2 = New Form2
       frm.SetDataSourceToReport(Me.dataset)
       frm.Show()
   End Sub
 
End Class

Hope this helps.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.