Some help pelease
Error line 48
If is value null error
{"Object reference not set to an instance of an object."}
System.NullReferenceException
System.Windows. Forms.DataGridViewCelll.Value.get returned null
Some help?
- private void pdfButton_Click(object sender, EventArgs e)
- {
- //Creating iTextSharp Table from the DataTable data
- PdfPTable pdfTable = new PdfPTable(prijava_radnikaDataGridView.ColumnCount -1);
- pdfTable.DefaultCell.Padding = 3;
- pdfTable.WidthPercentage = 100;
- pdfTable.HorizontalAlignment = Element.ALIGN_CENTER;
- pdfTable.DefaultCell.BorderWidth = 1;
- //float[] widths = new float[] { 0f, 18f, 40f, 35f, 35f, 25f, 25f, 18f, 40f, 35f };
- //pdfTable.SetWidths(widths);
- BaseFont bfCalibri = BaseFont.CreateFont("c:\\windows\\fonts\\calibri.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
- iTextSharp.text.Font calibri = new iTextSharp.text.Font(bfCalibri, 10, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.WHITE);
- iTextSharp.text.Font calibri2 = new iTextSharp.text.Font(bfCalibri, 9);
- //Adding Header row
- foreach (DataGridViewColumn column in prijava_radnikaDataGridView.Columns)
- {
- if (column.Index == 1)
- {
- }
- else
- {
- PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText, calibri));
- cell.BackgroundColor = new BaseColor(89, 135, 178);
- cell.VerticalAlignment = Element.ALIGN_MIDDLE;
- pdfTable.AddCell(cell);
- }
- }
- //Adding DataRow
- foreach (DataGridViewRow row in prijava_radnikaDataGridView.Rows)
- {
- foreach (DataGridViewCell cell in row.Cells)
- {
- if (cell.ColumnIndex == 1 )
- {
- PdfPCell cell2 = new PdfPCell(new Phrase(cell.Value.ToString().Split(' ')[0], calibri));
- pdfTable.AddCell(cell2);
- }
- else
- {
- PdfPCell cell2 = new PdfPCell(new Phrase(cell.Value.ToString(), calibri));
- pdfTable.AddCell(cell2);
- }
- }
- }
- etc.....code....<<
- }
Piyush PansuriyaPosted Dec 20, 2018, 4:06 AM
Goran BibicPosted Dec 20, 2018, 4:11 AM