Solved

how to use print dialog box?

Posted on 2000-05-17
19
303 Views
Last Modified: 2010-05-02
I have created a mdiform, which contains only menu bar. under which one
of the option is print and another is show.
I have created another new form and set the mdichild property to true. The child form is having list view control containing some data. I want to print the data of the list view control.
under the show click event, i am showing the child form which containing list view control.
In the print click event of menu bar i have done dialogbox.showprint. with the click event it is getting displayed but after pressing ok i am not getting any contents of list view control printed.

U please tell me how to tackle this problem.
0
Comment
Question by:rajiv_konx
  • 9
  • 6
  • 2
  • +2
19 Comments
 

Expert Comment

by:rizmughal
Comment Utility
Please explain in Detail
0
 
LVL 9

Expert Comment

by:GivenRandy
Comment Utility
You want to select the active form to do your activity.  For example, suppose frmMDI is your MDI parent and List1 is a ListBox on the child.  Then, you would reach the child ListBox control by:

frmMDI.ActiveForm.List1

0
 
LVL 2

Expert Comment

by:BobbyOwens
Comment Utility
You can't do it the way you are trying. What you'll need to do is print via the "Printer" object. You will need to programatically go through the listview control and do "Printer.Print", passing in the text you want to print.

The code below should do a basic print of a listview with 3 columns.

e.g.

Private Sub PrintListView()
 
  On Error GoTo PrintListView_Error

  Dim litData         As ListItem
  Dim strToPrint      As String
 
'Process listview
  For Each litData In lvwData.ListItems
'Get string to print (Assuming only 3 columns in listview)
    strToPrint = litData.Text & vbTab & litData.SubItems(1) & vbTab & litData.SubItems(2)
    Printer.Print strToPrint
  Next
'End Print
  Printer.EndDoc
 
PrintListView_Exit:
  Exit Sub
 
PrintListView_Error:
  MsgBox Err.Description, , "PrintListView"
  Resume PrintListView_Exit
 
End Sub


0
 
LVL 18

Expert Comment

by:mdougan
Comment Utility
Yes, just to clarify things a bit, the only purpose of the common dialog ShowPrint window is to pop up a dialog that will allow you to get input from the user about how many copies to  print, what pages to print, which printer to use etc.  Then, it's up to you to write the code retreive what the user entered in the dialog and to format the output as Bobby shows and print it.  

VB's built in support for printing is pretty limited, so, if you really need fancy printouts you might consider using Crystal Reports, or maybe a DataReport, or there is a pretty nice control from VideoSoft called VSView which is a sort of replacement for the VB Printer object.  You can download a free demo version of VSView from VideoSoft at

http://www.videosoft.com

it's a great control, but it's a bit pricey too.
0
 

Author Comment

by:rajiv_konx
Comment Utility
BobbyOwens,
        Thanks for the information. But i want to print the contents in the tabular format. i.e if the list view control has 3 headers then i want a table with 3 columns and as many rows the paper can fit. In the columns i want to print the actual contents of the list items. I will give the sizes of the columns depending on the number of column headers.
 Please help me out of this.
0
 
LVL 2

Accepted Solution

by:
BobbyOwens earned 100 total points
Comment Utility
What you'll need to do is going to be more complicated. You'll need to use the "CurrentX" property.

First of all, do something like the following (Notice the semicolons so that a new line isn't done every time):

printer.print lvwMain.ColumnHeaders(1).Text;
printer.currentX=50
printer.print lvwMain.ColumnHeaders(2).Text;
printer.currentX=150
printer.print lvwMain.ColumnHeaders(3).Text
printer.currentX=250

The last print statement doesn't have a semicolon at the end because you want the printer to go to a new line. You will need to adjust the "CurrentX" coordinate according to the widths you require. I only uses the numbers above to illustrate moving across the page.  This should print in tabular form but without the gridlines.


0
 
LVL 18

Expert Comment

by:mdougan
Comment Utility
Again, you might try to download the demo of the VideoSoft VSView Control.  It makes printing tabular or report formats much easier than the Printer object.  The VSView control will handle pagination and allow you to define page headers and footers, margins, fonts and many other items.  If  the thing you're printing happens to be a VideoSoft VSFlex table, then printing it is even easier.
0
 

Author Comment

by:rajiv_konx
Comment Utility
mdougan,
 i agree that common dialog showprint dialog box is just to take input from the user. I need pages option button to be enabled , so that in the edit boxe's from and to i can enter the page numbers. For this i have set the flag property to cdlPDPageNums. even after doing this pages option is not being enabled. please tell me how to enable the option.
0
 
LVL 2

Expert Comment

by:BobbyOwens
Comment Utility
This should do the trick:

CommonDialog1.Flags = CommonDialog1.Flags Or cdlPDPageNums
CommonDialog1.Max = 50
CommonDialog1.Min = 0
CommonDialog1.ShowPrinter

You need to set the minimum and maximum pages to print as well
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:rajiv_konx
Comment Utility
before obly I have done that but could not succeed with cdlPDPageNums
0
 
LVL 2

Expert Comment

by:BobbyOwens
Comment Utility
I'm afraid I didn't understand the last comment. Are you saying you've tried that and it didn't work. If so, ensure that you are setting the flags before the max and min.
0
 

Author Comment

by:rajiv_konx
Comment Utility
BobbyOwens,
       Everything is fine and i am able to print what i wanted. but i am facing problem with print to file check box of the printer dialog box.
      Rather than printing directly i want to print to a file.
please tell me how to go for this.
0
 
LVL 2

Expert Comment

by:BobbyOwens
Comment Utility
To find the checkbox value, you need to do:

blnChecked = (CommonDialog1.Flags And cdlPDPrintToFile) > 0


Then you need to write code to print to a file in whatever format you want.
0
 

Author Comment

by:rajiv_konx
Comment Utility
BobbyOwens,
I think u did not get my question properly. I want to print to a file means i want to click the print to file check box in the dialog box,  later i will supply the save dialog box so that he can save that file anywhere. please note that the file generated will be binary file not text file. later he can goto the dos prompt and print the file.

Please see any application having the print option so that u will get clear picture of what i want.
0
 
LVL 2

Expert Comment

by:BobbyOwens
Comment Utility
What you'll need to do is reopen the common dialog control using the "Save" action. Set the file type as PRN, and filter accordingly.

I don't know how to create a true PRN file. You could create a normal binary file using the "Open" method, but I don't know how you'll get DOS to print the file.
0
 

Author Comment

by:rajiv_konx
Comment Utility
BobbyOwens,
I think u did not get my question properly. I want to print to a file means i want to click the print to file check box in the dialog box,  later i will supply the save dialog box so that he can save that file anywhere. please note that the file generated will be binary file not text file. later he can goto the dos prompt and print the file.

Please see any application having the print option so that u will get clear picture of what i want.
0
 

Author Comment

by:rajiv_konx
Comment Utility
I am sorry i want to create true file i.e prn. if u can u pls tell me.
what ever u said i can do only if true prn is created.
0
 

Author Comment

by:rajiv_konx
Comment Utility
Comment accepted as answer
0
 

Author Comment

by:rajiv_konx
Comment Utility
Thanks for helping me in solving this problem.
I have got what ever i wanted
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now