473,671 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

code for printing database on datagrid view

33 New Member
pls i designed a database application using visual basic. i have done the coding for the print incase i want to print out the data.

Pls my problem is how to code at design time for the application to print the data in a tabular form. for now the records prints ontop of each other, i want the records and the field separated by rows and cells of a table as normal.

I used Ms access to design the database and the data is displayed by datagrid view. my code so far is as shown below. pls help me make correction to be able to achieve the above display

Expand|Select|Wrap|Line Numbers
  1. Public Class AccountView
  2.  
  3.     Private Sub BtnPDVPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPDVPrint.Click
  4.         Dim print_document As PrintDocument = PreparePrintDocument()
  5.  
  6.         print_document.Print()
  7.         If dlgPrint.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
  8.             dlgPrint.Document.Print()
  9.         End If
  10.     End Sub
  11.     Private Function PreparePrintDocument() As PrintDocument
  12.  
  13.         ' Make the PrintDocument object.
  14.  
  15.         Dim print_document As New PrintDocument
  16.  
  17.         ' Install the PrintPage event handler.
  18.  
  19.         AddHandler print_document.PrintPage, AddressOf Print_PrintPage
  20.  
  21.         ' Return the object.
  22.  
  23.         Return print_document
  24.  
  25.     End Function
  26.     Private Sub Print_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
  27.         Dim i As Integer = 0
  28.         Dim j As Integer = 0
  29.         Dim k As Integer = 70
  30.         Dim P As Integer = 320
  31.  
  32.         Dim imagePrint As Image = cd.Image
  33.         Dim AA As Integer = Integer.Parse(imagePrint.Height.ToString)
  34.         Dim tableFont As Font = New Font("Georgia", 14, FontStyle.Bold)
  35.         Dim tableFont1 As Font = New Font("Georgia", 12, FontStyle.Regular)
  36.         Dim tableFont4 As Font = New Font("Georgia", 11, FontStyle.Regular)
  37.         Dim tableFont2 As Font = New Font("Times New Roman", 12, FontStyle.Bold)
  38.         e.Graphics.DrawImage(imagePrint, 40, -70, imagePrint.Width, imagePrint.Height)
  39.         e.Graphics.DrawString(LblPDV.Text, tableFont, Brushes.Black, 350, 129)
  40.         e.Graphics.DrawString("NAME OF CLIENT", tableFont2, Brushes.Black, 70, 239)
  41.         e.Graphics.DrawString("PURPOSE", tableFont2, Brushes.Black, 195, 239)
  42.         e.Graphics.DrawString("DATE", tableFont2, Brushes.Black, 320, 239)
  43.         e.Graphics.DrawString("TOTAL AMOUNT ", tableFont2, Brushes.Black, 450, 239)
  44.         e.Graphics.DrawString("AMOUNT PAID", tableFont2, Brushes.Black, 570, 239)
  45.         e.Graphics.DrawString("BALANCE", tableFont2, Brushes.Black, 695, 239)
  46.  
  47. 12:     Do Until j = gv.ColumnCount
  48.             e.Graphics.DrawString(gv.Item(j, i).Value.ToString, tableFont4, Brushes.Black, k, P)
  49.             k = k + 125
  50.             j = j + 1
  51.         Loop
  52.         k = 70
  53.         P = P + 40
  54.         j = 0
  55.         i = i + 1
  56.         If i < gv.RowCount Then GoTo 12
  57.  
  58.         e.HasMorePages = False
  59.  
  60.     End Sub
  61.  
  62.     Private Sub pprev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pprev.Click
  63.         ' Make a PrintDocument and attach it to
  64.  
  65.         ' the PrintPreview dialog.
  66.  
  67.         dlgPrintPreview.Document = PreparePrintDocument()
  68.  
  69.         ' Preview.
  70.  
  71.         dlgPrintPreview.WindowState = FormWindowState.Maximized
  72.  
  73.         dlgPrintPreview.ShowDialog()
  74.     End Sub
Jul 23 '08 #1
0 1553

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1714
by: JasmineC | last post by:
Hi there! I'm having some problems printing out my windows form. Here's what I need to do: I need to print a datagrid off a windows form, however the datagrid is bigger than screen. When I tried to print the datagrid, it only print whatever is on the screen and it cut off the rest. I'm not familiar with the print control at all. Can anyone give me some help?? Thanks in Advance! Jasmine
0
2083
by: Namratha Shah \(Nasha\) | last post by:
Hey Guys, Today we are going to look at Code Access Security. Code access security is a feature of .NET that manages code depending on its trust level. If the CLS trusts the code enough to allow it ro run then it will execute, the code execution depends on the permission provided to the assembly. If the code is not trusted wnough to run or it attempts to perform an action which doe not have the required permissions then its execution...
2
2299
by: Allen Davis | last post by:
I have some hierarchical data bound to a series of nested DataLists and DataGrids for which I'd like to be able to provide the end-user some targeted printing capabilities. By that I mean being able to send just one parent dataitem and all its children to the printer. Does anyone have any good suggestions for how to do this or where to look for ideas about how to accomplish it? Thanks
3
1250
by: NoSf3RaTu | last post by:
Is there a way to only print out the datagrid in a given web page? That is I have a datagrid on my web page but I would like to add a button that will only give me a page with the datagrid to print but nothing else. Thanks,
6
5502
by: Paolo Pignatelli | last post by:
I have an aspx code behind page that goes something like this in the HTML view: <asp:HyperLink id=HyperLink1 runat="server" NavigateUrl='<%#"mailto:" &amp; DataBinder.Eval(Container.DataItem,"StoreEmail") &amp; "&amp;Subject=" &amp; DataBinder.Eval(Container.DataItem,"ProductName") ....
0
1132
by: RRKV | last post by:
Hi I have a datagrid which contains 4 rows and a checkbox. when the checkbox is selected and click the print button it should create an .aspx page which contains all the data and directly goes to the printer. (It should create this .aspx page in some Temporary folder since client doesn't want to view it before printing). Another Problem is from the datagrid i will get a value which should be assigned to the no of copies property of...
5
7100
by: ComputerStop | last post by:
I am attempting to print a datagridview. I have not found any method that works successfully. Has any one been successful with this?
5
3868
hussaini
by: hussaini | last post by:
please tell me any 1 printing code in datagrid in visual basic 6 in detail ----- Hello seniors members hope u will tell me ..... i have created a form in visual basic 6 so in the form there is a datagrid and a command button so i want to print the records in datagrid when i press that command button it open dailog like ms word CTRL + P its open of printing dailog hope u understand what i meant
1
2489
by: sonicfun2006 | last post by:
I have SQL Server Database and MS Access 2003 is connected with ODBC. I have very large amount of records in various tables. The database is very dynamic as it changes every minute. I’m trying to have a live MS Access report which would pull data from SQL Server. I’ll try to explain how I’m trying do this: The Access report should have two parts: 1. Title page report, just like table of contents. It should be listing a particular field of a...
0
8471
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8388
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8593
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8663
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7423
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5687
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1799
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.