473,387 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to print a ListView control?

Does anyone have an example of how I could print a ListView control? It'd
sure be easier to do this than to try to format the output in DrawStrings...

Thanks.
Nov 21 '05 #1
2 4440
Hi,

Sorry I dont have a code sample but graphics class has a drawstring
overload with accepts a rectanglef and stringformat. You can use that to
align the data properly on the page.

http://msdn.microsoft.com/library/de...ringtopic4.asp

Ken
--------------------
"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Does anyone have an example of how I could print a ListView control? It'd
sure be easier to do this than to try to format the output in
DrawStrings...

Thanks.

Nov 21 '05 #2
JR
I use this one, prints the collors but it dosn't work with column replaceces

in the form:

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e
As System.Drawing.Printing.PrintPageEventArgs) Handles
PrintDocument1.PrintPage

psPrintListView(ListView1, sender, e, , , True)

End Sub

'---------------in a mod
file----------------------------------------------------------

Module ModPrint

Public intBezig As Integer

Public Sub psPrintListView(ByVal ListViewToPrint As ListView, ByVal sender
As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs,
Optional ByVal Y As Integer = 0, Optional ByVal blnHeaders As Boolean =
True, Optional ByVal blnKleur As Boolean = True)

Dim nKolom As Long

Dim lvi As ListViewItem

Dim nLVI As Integer

Dim X, Y1, nLengte As Integer

Dim sTekst As String

Dim brsBorstel As Brush

Try

If e.PageSettings.Color = False Then blnKleur = False 'Als printer geen
kleur ondersteunt altijd in zwart-wit

If intBezig = 0 AndAlso blnHeaders = True Then

X = 0

For nKolom = 0 To ListViewToPrint.Columns.Count - 1

sTekst = ListViewToPrint.Columns(nKolom).Text

Do While e.Graphics.MeasureString(sTekst, ListViewToPrint.Font).Width >
ListViewToPrint.Columns(nKolom).Width

sTekst = sTekst.Remove(sTekst.Length - 1, 1)

Loop

nLengte = e.Graphics.MeasureString(sTekst, ListViewToPrint.Font).Width

Select Case ListViewToPrint.Columns(nKolom).TextAlign

Case HorizontalAlignment.Center

e.Graphics.DrawString(sTekst, ListViewToPrint.Font, Brushes.Black, X +
(ListViewToPrint.Columns(nKolom).Width - nLengte) / 2, Y)

Case HorizontalAlignment.Right

e.Graphics.DrawString(sTekst, ListViewToPrint.Font, Brushes.Black, X +
ListViewToPrint.Columns(nKolom).Width - nLengte, Y)

Case HorizontalAlignment.Left

e.Graphics.DrawString(sTekst, ListViewToPrint.Font, Brushes.Black, X, Y)

End Select

X += ListViewToPrint.Columns(nKolom).Width

Next

Y += e.Graphics.MeasureString(" ", ListViewToPrint.Font).Height 'Verhoog Y
met de hoogte van 1 lijn

End If

For nLVI = intBezig To ListViewToPrint.Items.Count - 1

lvi = ListViewToPrint.Items(nLVI)

X = 0

For nKolom = 0 To ListViewToPrint.Columns.Count - 1

sTekst = lvi.SubItems(nKolom).Text

Do While e.Graphics.MeasureString(sTekst, ListViewToPrint.Font).Width >
ListViewToPrint.Columns(nKolom).Width

sTekst = sTekst.Remove(sTekst.Length - 1, 1)

Loop

nLengte = e.Graphics.MeasureString(sTekst, ListViewToPrint.Font).Width

If blnKleur Then

brsBorstel = pfBorstel(lvi.SubItems(nKolom).ForeColor)

Else

brsBorstel = Brushes.Black

End If

Select Case ListViewToPrint.Columns(nKolom).TextAlign

Case HorizontalAlignment.Center

e.Graphics.DrawString(sTekst, ListViewToPrint.Font, brsBorstel, X +
(ListViewToPrint.Columns(nKolom).Width - nLengte) / 2, Y)

Case HorizontalAlignment.Right

e.Graphics.DrawString(sTekst, ListViewToPrint.Font, brsBorstel, X +
ListViewToPrint.Columns(nKolom).Width - nLengte, Y)

Case HorizontalAlignment.Left

e.Graphics.DrawString(sTekst, ListViewToPrint.Font, brsBorstel, X, Y)

End Select

X += ListViewToPrint.Columns(nKolom).Width

Next

Y += e.Graphics.MeasureString(" ", ListViewToPrint.Font).Height 'Verhoog Y
met de hoogte van 1 lijn

If Y > e.MarginBounds.Height Then

Y1 = Y

Y = 0 'reset Y anders niets dan lege bladen

intBezig = nLVI + 1 'Bepaal waar volgend blad begint

e.HasMorePages = True

Exit For

End If

Next

If nLVI >= ListViewToPrint.Items.Count Then

intBezig = 0

End If

X = 0

e.Graphics.DrawLine(New Pen(Color.Black), X, 0, X, Y)

For nKolom = 0 To ListViewToPrint.Columns.Count - 1

e.Graphics.DrawLine(New Pen(Color.Black), X, 0, X, Y1)

X += ListViewToPrint.Columns(nKolom).Width

Next

e.Graphics.DrawLine(New Pen(Color.Black), X, 0, X, Y1)

Catch ex As Exception

MsgBox("Foutje: " & ex.Message)

End Try

End Sub

Public Function pfBorstel(ByVal clr As Color) As Brush

Dim myBrush As SolidBrush

myBrush = New SolidBrush(clr)

Return myBrush

End Function

End Module

'end code

"Ken Tucker [MVP]" <vb***@bellsouth.net> schreef in bericht
news:OA*************@TK2MSFTNGP15.phx.gbl...
Hi,

Sorry I dont have a code sample but graphics class has a drawstring
overload with accepts a rectanglef and stringformat. You can use that to
align the data properly on the page.

http://msdn.microsoft.com/library/de...ringtopic4.asp

Ken
--------------------
"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Does anyone have an example of how I could print a ListView control?
It'd sure be easier to do this than to try to format the output in
DrawStrings...

Thanks.


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Welie | last post by:
Hi all- I am using a listview (MSComctlLib.ListViewCtrl.2)on an Access form. Actually there are six listviews on the form. I need to do the same thing to all six forms so I have the loop below....
1
by: newbie | last post by:
Hello, I maybe asking too much in a single posting, but here it goes: I building a windows form that mimic's the Outlook XP GUI. Its a three pane form that will allow a user to view and edit...
2
by: Ken | last post by:
Hi all, Please help! I'm attempting to apply tooltips to each individual item in VB.Net's Listview control. In VB6 it was easy - you just did the following (assumes "myListView" is the name of...
7
by: BobAchgill | last post by:
I am trying to decide which of these controls to use to implement letting my user select a full row from MyList. The MyList has several columns which would be nice to sort by at run time. The...
3
by: Michael.Suarez | last post by:
Is it me, or does it seem like they put no effort into creating the listview control in .Net. listview. A few gripes I have with .Net listview that aren't present in vb6: -Inability to set...
12
by: garyusenet | last post by:
I have had no replies to my previous post so perhaps I didn't write it good enough. Please excuse new thread but i wanted to break from the last thread hopefully this thread will be better. ...
10
by: Rob | last post by:
VS 2005 How can you tell if a value is contained in a specific column (let's say column 1 named Status) of a ListView ? In a list box you could go... If ListBox1.Items.Contains(strWhatever)...
5
by: Mark Olbert | last post by:
How do I get the DataPager and ListView to play nice together when I use a custom datasource? In my webpage, I use linq to pull data from a SqlServer database and assign the resulting...
4
by: Brian Gaze | last post by:
I have created a ListView control and have bound this to a datasource. Within the ItemTemplate of the ListView I have added another ListViewControl which is databound in the code behind. The idea...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.