English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

My listview control contains Slno, Particulars, Qty, Rate, Amt. The data inside it should be printer in proper tabulated form - text left alighned and numbers right aligned. Please provide a good answer for me.

2007-01-08 14:08:14 · 3 answers · asked by Krishnadas P 1 in Computers & Internet Programming & Design

My LIstview contains slno, Item, Qty, Rate, Amount. I need to get the printer output in tabulated form Numbers right aligned and text left aligned. It would be helpful if you give the answer as the source code.

2007-01-10 15:04:04 · update #1

3 answers

Use Report Manger to Print your Visual Basic Document

2007-01-08 20:12:36 · answer #1 · answered by nir k 2 · 0 0

Hello,

For printing anything from VB, we have to use Printer Class (which is by default). For Example, if you want to print a line in the click of the button, use this printer class like this.

Printer.Print "Hello, This is from VB"

So Printer object is the main thing you have to use. Please look at this link below for more information, that have explained more on this pattern
http://p2p.wrox.com/topic.asp?TOPIC_ID=50294

Here, there are two ways to approach.
1) With using proper font which is as same as for the screen and for printer (like Courier New, for example) and placing the content in the tabular format with well equally placed content length.

2) With X and Y Co-ordinates. where the logic is completely dependent on the X and Y co-ordinates of the page. So here
fixing the X (Column and its position) and keep changing Y (Row for each item in the list view)

Both needs work, They are not so easy to print just like that, but it can be achieved by some amount of work.

Example in brief...

FOR #1)

Considering columns as you specified "Slno, Particulars, Qty, Rate, Amt."

a) SlNo: May be 3 digits or 4 digits, so from 001 to 999 OR 0001 to 9999,
That will be.....
VBCODE:
Right(" " & iSlNo, 4)
" " -> 4 blank spaces
iSlNo -> Iterator that you will be printing
and that "4" is the content length to retrieve

for 9 it will be " 9" and
for 99 it will be " 99" and
for 999 it will be " 999" and
for 9999 it will be "9999"

If you look properly, see the numbers are equally placed with and the length remains same. that is 4

b) Particulars: Max 30 chars
Here Use function "Left" to set the content length and Right is used basically for numbers
Left("<30 Blank spaces"> & sParticular, 30)
So if the Particular is
"Monitor" then it becomes 7(length of the "monitor" word) + 23 blank spaces

c) Qty: 2-digits to 3-digits (same as #a)

d) Rate: 8(5 and 1 and 2)
5 for before decimal (99999)
1 for decimal "."
2 for after decimal (99)
Like 99999.99

e) Amt: same as #d

So here the content is equally placed with its length and printed with printer fonts (as same as for screen and printer, like Courier New). So the Content looks tabulated and equally placed.

This is bit childish way to approach, but okay, with output. :)

FOR #2)

As above mentioned Columns "Slno, Particulars, Qty, Rate, Amt."
Here we use X any Y Co-ordinates to place the content of the list view.

For first Line (Column Header)
Y = 300; X = 0 for beginning of SlNo
Y = 300; X = 1500 for beginning of Particulars
Y = 300; X = 5000 for beginning of Qty
Y = 300; X = 5600 for beginning of Rate
Y = 300; X = 7000 for beginning of Amt

Now 1 line is printed, for going to next line, increase the Y by 300
so, Y = 600 for 2nd line and 900 for 3rd line. This process should be in the complete loop and you have to reset before you call of NewPage, so printer starts printing from the beginning of the new page. Please be careful with the values you set, make sure twice before you attempt to print.

NOTE: PLEASE DO NOT HARD-CODE THESE VALUES, they have to be set logically and at the run time.

So in #2, X and Y position are fixed, and automatically it will be tabulated and looks ordered.

Okay, this gives you an outline of the process. and rest is your work.

Hope this helps.

2007-01-09 00:02:57 · answer #2 · answered by Raghavendra Mudugal 3 · 0 0

Try this:
Dim x as integer

For x = 0 to listview1.count - 1
Printer.Print Listview.list(x)
Next

This will work with a listbox with 5 columns...not sure about a listview control

2007-01-08 23:37:41 · answer #3 · answered by rod 6 · 0 0

fedest.com, questions and answers