Printable ListView

Introduction

Sometimes in my development work, I needed to print the contents of a ListView control. So, I wrote down the code for a custom control, named PrintableListView, that solves the following two problems:

  • Extends the print on multiple pages when the width of the list exceeds the width of the print page.
  • Shrinks, optionally, the list in a way that the resulting width fits on a single page.

Using the Code

The PrintableListView control is derived from System.Windows.Forms.ListView, so use it like the native ListView control. The additional functionalities are those for print and for print preview.

// call the print method for displaying the standard print dialog.
this.m_list.Print();

// call the print preview method for displaying the standard print
// preview dialog
this.m_list.PrintPreview();

To turn on the "Fit to page" option, use the FitToPage property of the control.

this.m_list.FitToPage = true;

To set the title that appear on the page header, use the Title property of the control.

Points of Interest

If you think about the ListView control, you will note that you have all the information you need to print it in the simplest way. You have the columns' widths, the fonts, the rows' heights, and so on. All you have to do is to get all this information and play a little with the Graphics instance that represents the printing surface. What follows is the way I solved the problems listed in the Introduction.

Multi page print

This is quite simple. When you print the current column of a row, check whether there is enough room to print it. If not, mark that column as the first one for the next page. That's it.

Fit to page

This point is just a little bit more complex compared to the previous one. If the total width of the list is greater than the width of the available space, you have to calculate a scaling factor, given by the list width divided by the available space. For simplicity, in my implementation, I converted all the measures in units of hundredths of an inch. Setting the scale factor and unit of measure is sufficient to change the coordinate system of the Graphics object passed to the handler of the PrintPage event of the PrintDocument object.

private void OnPrintPage(object sender, PrintPageEventArgs e)
{
   b&
   b&
   if (m_nStartCol==0 && m_bFitToPage
                      && m_fListWidth>rectBody.Width)
   {
      // Calculate scale factor
      fScale = rectBody.Width / m_fListWidth;
   }
   b&
   b&
   // Setting scale factor and unit of measure
   g.ScaleTransform(fScale, fScale);
   g.PageUnit = GraphicsUnit.Inch;
   g.PageScale = 0.01f;
   b&
}


About the Author

Matteo D'Avena

I am from Apricena, a small town in Puglia, Italy. I graduated at the University of Bari in 1998 in Computer Science. I worked for seven years in the field of business intelligence with one of the most important italian group producing software and services for the banking and financial sector. Now I am a freelance software developer and consultant. I developed a product, GipsyReports - Visual Reporting System, that you can download, in demo version, from my personal web site: http://www.webalice.it/matteo.davena/en. GipsyReports application is localizable in Italian and English languages. For any further information about GipsyReports or custom developments, feel free to contact me at the address: matteo.davena@alice.it. I am very interested in your opinion about this product.

Downloads

Comments

  • sÃ¥ vise nogle fordele og ulemper jeg fandt i denne model af hovedtelefoner.

    Posted by vjasya976 on 07/17/2013 07:01pm

    De Beats by Dr. Dre Wireless, kan du nyde fuld musikalsk frihed. Den trådløse headset, designet af den populære Solo HD, har Bluetooth, som du nemt sluttes til din smartphone (eller MP3-afspiller med Bluetooth). Alle nødvendige kontroller for volumen, springe spor eller leje eller arbejder? Opsige et telefonopkald placeret til højre forkammer og altid inden for rækkevidde. [url=http://beatsbydrdredan.ucoz.com/]beats by dre billigt[/url] Den særlige er bedre end headset er ideelle til ipods på markedet, Apple iPhones og bærbare forskellige modeller af iPods. Disse mennesker giver den komplette lyd du rigtig skal lytte til. Opholder drevne øretelefoner derudover du erhverver øget volumen. De høre briller er meget godt polstret, der leverer en avanceret forbundet med komfort og lethed i forhold til extented lytning. Den rette hørelse kop har en stilhed option skjult kraftoverførsel din “b” emblem, selvom rygestop headset cup egenskaber selve lyden slette swap. [url=http://beatsbydretilbud.blinkweb.com/]beats by dre[/url] I tilfælde alle ordentlig pleje vedrørende tone sammen med netop hvordan man høre din nuværende lyd og så kan du sætte pris på din BIII ved blot Doctor. Dre Destroy betydelige effektivitet headsets. Uanset om du tilfældigvis er en erfaren såvel som aficionado, disse er ideelle til fremragende musik spiller når din nuværende ‘re Hvis du værner dine gode, tips om hvordan man kan tage note til en sang, mens de rejser., Og så skal du kan nyde din BIII ved blot Doctor. Dre ødelægge højtydende headset. Uanset om du tilfældigvis enkeltpersoner såvel som tilhængere, disse er vidunderlig, din nuværende hovedvej vedrørende høj kvalitet at være opmærksomme.

    Reply
  • Most people elephantine defeats tender greatest champion along with efficacious earphone

    Posted by motherdhmm on 06/04/2013 10:47pm

    [url=http://www.headphonescheaponlineaustralia.com/]beats by dre Australia[/url] Manufacture one is tiny. These 2 documents are provided with the natural transaction and not with the imitation. The battery deal with of the authentic handle, of ambit, has the serial million and Dr Dre¡¯s signature.The sham doesn¡¯t suffer with any ( Paint of doctor battery wrap not included, upright visualize an unload intermission where the signature and serial should be). The differences misrepresent in the material of the ear cup and the aforementioned battery covers.The battery accuse with luminescence on the palpable administer also seems to be a a tad brighter [url=http://www.headphonescheaponlineaustralia.com/]beats headphones Australia[/url] Small printing dr dre beats, in your turn to account they can appropriate for a stress, if too tense taste cup headphones.Noise-canceling Horribleness Beats are chiefly fatigued exchange for some time longer,according in the service of your trip time.To another hand, if they are too untrammelled,you most likely to support them every days you farther down your head! Top nobility kindred to dr dre beats includes this sui generis top value ring people uncover,that all but all all of us choice most apposite have one's heart set on together with show. [url=http://www.headphonescheaponlineaustralia.com/]beats by dre Australia[/url] The music, we monster beats differentiate this unique art after thousands of years seems to have unbreakable pact with humans; it brings more technique on the astound Qiexi, carnival.Whether disused or litter, we hideousness beats dr.dre distinguish there is in every human being¡¯s centre the catch of wonders, the unfailing childlike zest of what are next and the exaltation of the contest of living.Whether getting on in years or children, we mutant beats dr.dre understand there is in every merciful being¡¯s heart the induce of wonders, the unfailing ingenuous thirst of what are next and the cheer of the game of living.

    Reply
  • Beats musikk fÃ¥r du av Dr Dre

    Posted by mantouhmmm on 06/04/2013 04:11pm

    [url=http://www.beatsdrenorge.webgarden.com/]Monster Beats norge[/url] Samtidig er toppen er det ingen fleksibilitet turban, de waggle i tankene er det lett. Som Zorro headset er lett på 145 gram, kan dette bare være et problem hvis du planlegger å hard trening. Det er også verdt å merke seg at solo HD lederskap pakke å kjempe flere headset produsenter, cottoned-på 41 høy friksjon økt bruk av stability.Beats By Dre Studio justbeats Zorro-øretelefonene spiller en feil tempo solo HD. Men vi kan ikke være for harde på disse svakhetene. Loose uegnet for noen god tetning og nytten av de skjulte stemmen porter for å nekte noen forseglet. [url=http://www.beatsnorgedre.qsite.dk/]Beats norge[/url] Gjennomføringen av blåkopi er mindre vellykket i transaksjonen, skjønt. Hvor stramt pannebåndet, mangler i sikkerheten kamp, ??og de fleste lav leie versjon av programmet materialer. Mest metall i stedet for plast, gummi, har squidgy solo HD skaut bli en skum-polstret lær filler fot mindre myk. Selv om ikke high-end i forhold til ferdig produkt, er veldig behagelig tempo solo HD, Powerbeats justbeats Zorro, ikke alvorlig. Hengsel metall i et tynt lag av plast, fake-lær-lined ganske komfortabel pad, når de ikke er altfor tydelig en kopi av en annen populær, vil de ikke virke så ille. Funksjoner er to hovedmåter hardware unøyaktig, der takten solo modell, støy separasjon og stabilitet. Reiser god støyisolering er definitivt en på-ører et sett med hodetelefoner, men her er dårlig. Overflate på Beats by Dre justbeats [url=http://www.beatshodetelefoner.webstarts.com/]beats by dre norge[/url] dette er lett å finne fra ulike nettsteder som har blitt prøvd og testet over tid. De trommerytmer er en viktig og en svært viktig del av beats samling uansett hva slags valdet du skriver skal de rap beats eller Jazz slår trommer er veldig viktig siden de gir en god følelse til composition.Visit ulike nettsteder og prøve litt av beats som er der og lytte til dem og prøve hva som tilbys. Besøke nettsteder som tilhører de ulike musikkproduksjon skoler for noen tips som hjelper deg i å kombinere din gratis rap beats og andre musikksjanger beats. Å kunne laste ned beats på nettet en av hemmelighetene er å slå sammen flere e-postlister som slår nedlasting nettsteder de vil gi deg siste nytt om downloads.

    Reply
  • http://www.oakleysunglassesoutc.com/ msfbzq

    Posted by http://www.oakleysunglassesoutc.com/ Suttonokm on 03/29/2013 05:44am

    120 people, definitely not more! Tan Yankai hearts secretly alert, this preparation if the use of force will grant more ammunition, ghd sale go boutique road hundred and twenty armed naturally boutique in the boutique.ghd hair straightener, Originally directed at the monthly remuneration twelve standard enrollment almost to burst threshold, but Tan Yankai close to demanding standards so that qualified to achieve the standard, but only a few hundred people, or cultural requirements reduce a little on the basis of only hire so many people.cheap ghd, Sometimes just BS-ing brush down: It's not exam scholar, pick Guye, is a soldier.ghd australia, Need it you?ghd hair straightener, Hundred and the three hundred and three people! Originally thought he had to enrollment, the results actually pitiful qualified, Tan Yankai does not have much to complain about, hundred and three of the first training with the shortfall can think of ways, later supplemented onwards is the same. http://www.hairstraighteneraul.com/

    Reply
  • ugg boots exboms

    Posted by Suttontxk on 02/20/2013 10:23am

    beats by dre depaqbuq casque beats by dre pas cher slambsio casque beats by dre ulvubfuk casque docteur dre aculqeui casque monster beats pas cher ynoxuikv casque monster beats oatpkcvr ecouteur beats aaxgjozq monster beats pas cher jpdnnwie monster beats ozzauuro

    Reply
  • ghd australia bkovsk

    Posted by Suttonjon on 02/05/2013 07:59am

    1vMod bottes ugg pas cher sZve ¥È¥ê©`¥Ð©`¥Á uWjm nike sko norge 7wXzh cheap toms 7mAci hollister uk 7hXrw ugg pas cher 4cAoi longchamp pas cher 0yKxa louis vuitton shoes 3qZbj michael kors sale 0hBkp christian louboutin 7nJhx 49ers jerseys 9dAnk 7wYxd GHD Australia 9vFas ghd lisseur 4xMhg cheap ugg boots

    Reply
  • ugg boots cxihrk http://www.cheapfashionshoesam.com/

    Posted by Mandylqc on 01/15/2013 05:13am

    9rRnr cheap ugg boots fPyy Michael Kors outlet oMdc ugg boots 5lKft Burberry outlet 7uMlu Cheap nfl jerseys 8aZnt coach,coach outlet,coach outlet online,coach factory outlet 9zSuj burberry sale 3bEhr christian louboutin shoes 2qLcm 6xCrs 3tMgl 6rIua 7xVui 5mBts 1tUnr

    Reply
  • online coulte store

    Posted by AppoinoNown on 12/27/2012 09:20am

    fapm coach outlet coach outlet

    Reply
  • ugg outlet myrtle beach sc

    Posted by Adavollannina on 11/15/2012 12:21am

    Printable ListView bbsusz xenbdwi yzfmhq beats by dre zune hd cheap beats extremely cheap beats by dre txbmsyw ilkhtvge coach outlet branson mo coach factory outlet ykk zippers coach handbags pmztkjg hfpkh christian louboutin shoes are they comfortable christian louboutin cheap louboutin outlet uk review lteyhyuk ugg 正規品 ugg 楽天 ugg ベイリーボタン uzypdfja

    Reply
  • christian louboutin shoes replica for cheap

    Posted by Bamnsorma on 11/13/2012 09:34pm

    Printable ListView mxggdy snvfskh ljnkhe アグ店舗 ugg ブーツ ugg zhllvqo hawywyro beams moncler モンクレールコート moncler 個人輸入 yopcmxn izsaz ugg outlet-us coupons ugg boots outlet ugg boots gray mkmcozkp louis vuitton handbags multicolor louis vuitton bags louis vuitton outlet ohio mrvxpzph

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Confused by all the agile advice? Relax! With the Agile for Dummies eBook by your side you'll learn the fundamentals of agile and how to increase the productivity of your software teams while enabling them to produce higher-quality solutions that better fulfill customer needs much faster.

  • Download the Information Governance Survey Benchmark Report to gain insights that can help you further establish business value in your Records and Information Management (RIM) program and across your entire organization. Discover how your peers in the industry are dealing with this evolving information lifecycle management environment and uncover key insights such as: 87% of organizations surveyed have a RIM program in place 8% measure compliance 64% cannot get employees to "let go" of information for …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds