1 Replies - 1124 Views - Last Post: 03 February 2012 - 05:48 AM Rate Topic: -----

#1 Ozzy18  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 04-October 11

VB.Net printing within specific columns.

Posted 03 February 2012 - 02:30 AM

Hello , I need some help with my printing from my data grid.
Basically I can get all the data within the grid present in the "print preview" however they are not within the right columns , and all the data overlaps , making the printout look very messy ! :(

I need to be able to get all the data into their specific columns , e.g all the names under the name column .

This is my code so dar =] ( its rather long , so please bare with me !)




   PrintDocument1.DefaultPageSettings.Landscape = True

        Dim Myfont As New Font("Courier New", 10, FontStyle.Regular)
        Dim MyFontSmall As New Font("Courier New", 8, FontStyle.Regular)
        Dim MyFormat As String = "{0,-6}{1,-12}{2,-12}{3,-8}{4,-23}{5,-12}{6,-20}{7,-20}{8,-6}"
        Dim LineToprint As String
        Dim X, Y, FontHeight As Integer
        X = 10
        Y = 50
        FontHeight = Myfont.GetHeight(e.Graphics)

        e.Graphics.DrawString("List Of all customers", Myfont, Brushes.Black, X, Y)
        Y = Y + FontHeight
        e.Graphics.DrawString("", Myfont, Brushes.Black, X, Y)
        Y = Y + FontHeight
        LineToprint = String.Format(MyFormat, "Name", "Last Name", "Address", "Email", "House phone Number", "Mobile", "Size Of pool", "Size Of sattelite", "CustomerID")
        e.Graphics.DrawString(LineToprint, Myfont, Brushes.Black, X, Y)
        Y = Y + FontHeight
        e.Graphics.DrawString("", Myfont, Brushes.Black, X, Y)


        Dim DtCustomers As New DataTable()
        Dim CustomerColumnIndex, CustomerRowIndex, index As Short
        DtCustomers = CustomersDs.Tables(0)

        For CustomerColumnIndex = 0 To DtCustomers.Rows.Count - 1
            Y = Y + FontHeight
            X = 10

            For CustomerRowIndex = 0 To DtCustomers.Columns.Count - 1

                LineToprint = DtCustomers.Rows(CustomerColumnIndex)(CustomerRowIndex).ToString

                e.Graphics.DrawString(LineToprint, MyFontSmall, Brushes.Black, X, Y)


                X = X + 100

            Next CustomerRowIndex

        Next CustomerColumnIndex

This post has been edited by Atli: 03 February 2012 - 03:32 AM
Reason for edit:: Please use [code] tags when posting code.


Is This A Good Question/Topic? 0
  • +

Replies To: VB.Net printing within specific columns.

#2 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

Re: VB.Net printing within specific columns.

Posted 03 February 2012 - 05:48 AM

can you send the picture of messy print preview?
if they are not within the right columns maybe there is the problem with for-loops..try put For-Next CustomerRowIndex outside For-Next CustomerColumnIndex
For CustomerRowIndex = 0 To DtCustomers.Columns.Count - 1	 
     For CustomerColumnIndex = 0 To DtCustomers.Rows.Count - 1	      	 
	        
     Next CustomerColumnIndex
Next CustomerRowIndex


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1