As I said before, if there is empty in the datagridview-cell, the type of this cell is null, so the reason of this error message is there are some empty cells and I guess they belong to the last line. But I guess maybe not only the last line is empty, other cells may also be empty, so you can determine whether it is empty and if so, replace it with a specific character:. This can be beneficial to other community members reading this thread. You only output data for each row of cells in datagridview without outputting the data for each column header, I suggest you can add it:.

Author:Dulrajas Gushura
Country:Czech Republic
Language:English (Spanish)
Published (Last):15 December 2013
PDF File Size:3.72 Mb
ePub File Size:9.26 Mb
Price:Free* [*Free Regsitration Required]

Home Categories. Need Help? Our Support Team is here to help. Ask Question. Form Controls. You will need to import the following namespaces. Imports System. Imports iTextSharp. Populating DataGridView. InitializeComponent ;. BindDataGridView ;. Add 1, "John Hammond" , "United States" ;. Add 2, "Mudassar Khan" , "India" ;. Add 3, "Suzanne Mathews" , "France" ;. Add 4, "Robert Schidner" , "Russia" ;. Public Sub New. End Sub. Dim dt As New DataTable. Add 1, "John Hammond" , "United States".

Add 2, "Mudassar Khan" , "India". Add 3, "Suzanne Mathews" , "France". Add 4, "Robert Schidner" , "Russia". Then a directory folder is created if it does not exists. This folder will be used to save the generated PDF file.

ColumnCount ;. HeaderText ;. Color , , ;. AddCell cell ;. AddCell cell. ToString ;. Exists folderPath. CreateDirectory folderPath ;. A2, 10f, 10f, 10f, 0f ;. GetInstance pdfDoc, stream ;. Open ;. Add pdfTable ;. Close ;. Object , e As System. Color , , If Not Directory. Exists folderPath Then. CreateDirectory folderPath.

End If. A2, GetInstance pdfDoc, stream. Add pdfTable. End Using. Related Articles. Add Comments. Thank you for the feedback. The comment is now awaiting moderation. You will be notified via email when the author replies to your comment. You can add your comment about this article using the form below.

Make sure you provide a valid email address else you won't be notified when the author replies to your comment Please note that all comments are moderated and will be deleted if they are Not relavant to the article Spam Advertising campaigns or links to other sites Abusive content.

Please do not post code, scripts or snippets. Required Invalid Email Address. Security code:. Required Invalid security code.

I declare, I accept the site's Privacy Policy. Add Comment. Disclaimer : The code samples and API available at www. You are free to use it for commercial as well as non-commercial use at your own risk, but you cannot use it for posting on blogs or other tutorial websites similar to www. All the code samples and API provided by the authors are solely their creation and neither the author nor the site are responsible if it does not work as intended.

I agree to the above terms. Download Required. What our readers say. Error Details. This site makes use of Cookies. Please refer Privacy Policy for more details. Got it.


Export datagridview data to pdf C#

Home Categories. Need Help? Our Support Team is here to help. Ask Question. Form Controls. You will need to import the following namespaces.


Export DataGridView Data To PDF In C#

By using our site, you acknowledge that you have read and understand our Cookie Policy , Privacy Policy , and our Terms of Service. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I have a problem while trying to get values of specific columns in dataGridView and add them to the PdtPtable. But the values added in the table is repeated, for example row one is added twice. I tried to go through each row and in every row through each column. I have fixed the indentation in your code snippet. You can now see what you're doing wrong in one glimpse.


Subscribe to RSS

In this blog, we will learn how to export DataGridView data to pdf using C code. Amit Mohanty Updated date, Aug 02, In this code example, we will learn how to export DataGridView data to a pdf file and save that in a folder using C code. In this program, first, we have to get connected to the database and fetch data from the DB and show it in the Data GridView like the below image. To do that, right-click on the project and select "Manage NuGet Package" menu. After that go to the "Browse" tab and search for iTextSharp and install it.



Related Articles