Table of Contents

Class GridCellLayoutEventArgs

Namespace
Syncfusion.Pdf.Grid
Assembly
Syncfusion.Pdf.Portable.dll

Represents the abstract class of the GridCellLayoutEventArgs.

public abstract class GridCellLayoutEventArgs : EventArgs
Inheritance
GridCellLayoutEventArgs
Derived
Inherited Members

Examples

// Creates a new document
PdfDocument doc = new PdfDocument();
RectangleF rect = new RectangleF(0, 0, 500, 50);
//Create DataTable for source
DataTable dataTable = new DataTable("myTable");
dataTable.Columns.Add("ID1");
dataTable.Columns[0].Caption = "id";
dataTable.Columns.Add("ID2");
object[] values = new object[] { "Roll Number", "Student Name" };
dataTable.Rows.Add(values);
values = new object[] { "011", "Cris" };
dataTable.Rows.Add(values);
values = new object[] { "011", "Clay" };
dataTable.Rows.Add(values);
PdfPage page = doc.Pages.Add();
PdfPageTemplateElement top = new PdfPageTemplateElement(rect);
PdfGrid table = new PdfGrid();
// Subscribe the cell layout event 
table.BeginCellLayout += new PdfGridBeginCellLayoutEventHandler(table_BeginCellLayout);
table.DataSource = dataTable;
table.Style.CellPadding = 16;
// Draws the table in page
table.Draw(page.Graphics);
doc.Save("Tables.pdf");
// Cell layout event handler
void table_BeginCellLayout(object sender, PdfGridBeginCellLayoutEventArgs args)
{
  if (args.RowIndex == 1)
  {
    args.Graphics.DrawRectangle(new PdfPen(PdfBrushes.Red, 2), PdfBrushes.White,args.Bounds);
  }
}
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
Dim rect As RectangleF = New RectangleF(0, 0, 500, 50)
'Create DataTable for source
Dim dataTable As DataTable = New DataTable("myTable")
dataTable.Columns.Add("ID1")
dataTable.Columns(0).Caption = "id"
dataTable.Columns.Add("ID2")
Dim values() As Object = New Object() { "Roll Number", "Student Name" }
dataTable.Rows.Add(values)
values = New Object() { "011", "Cris" }
dataTable.Rows.Add(values)
values = New Object() { "011", "Clay" }
dataTable.Rows.Add(values)
Dim page As PdfPage = doc.Pages.Add()
Dim top As PdfPageTemplateElement = New PdfPageTemplateElement(rect)
Dim table As PdfGrid = New PdfGrid()
' Subscribe the cell layout event 
AddHandler table.BeginCellLayout, AddressOf table_BeginCellLayout
table.DataSource = dataTable
table.Style.CellPadding = 16
' Draws the table in page
table.Draw(page.Graphics)
doc.Save("Tables.pdf")
' Cell layout event handler
Private Sub table_BeginCellLayout(ByVal sender As Object, ByVal args As PdfGridBeginCellLayoutEventArgs)
  If args.RowIndex = 1 Then
     args.Graphics.DrawRectangle(New PdfPen(PdfBrushes.Red, 2), PdfBrushes.White,args.Bounds)
  End If
End Sub

Properties

Bounds

Gets the bounds of the cell.

public RectangleF Bounds { get; }

Property Value

RectangleF

Examples

// Creates a new document
PdfDocument doc = new PdfDocument();
RectangleF rect = new RectangleF(0, 0, 500, 50);
//Create DataTable for source
DataTable dataTable = new DataTable("myTable");
dataTable.Columns.Add("ID1");
dataTable.Columns[0].Caption = "id";
dataTable.Columns.Add("ID2");
object[] values = new object[] { "Roll Number", "Student Name" };
dataTable.Rows.Add(values);
values = new object[] { "011", "Cris" };
dataTable.Rows.Add(values);
values = new object[] { "011", "Clay" };
dataTable.Rows.Add(values);
PdfPage page = doc.Pages.Add();
PdfPageTemplateElement top = new PdfPageTemplateElement(rect);
PdfGrid table = new PdfGrid();
// Subscribe the cell layout event 
table.BeginCellLayout += new PdfGridBeginCellLayoutEventHandler(table_BeginCellLayout);
table.DataSource = dataTable;
table.Style.CellPadding = 16;
// Draws the table in page
table.Draw(page.Graphics);
doc.Save("Tables.pdf");
// Cell layout event handler
void table_BeginCellLayout(object sender, PdfGridBeginCellLayoutEventArgs args)
{
  if (args.RowIndex == 1)
  {
    args.Graphics.DrawRectangle(new PdfPen(PdfBrushes.Red, 2), PdfBrushes.White,args.Bounds);
  }
}
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
Dim rect As RectangleF = New RectangleF(0, 0, 500, 50)
'Create DataTable for source
Dim dataTable As DataTable = New DataTable("myTable")
dataTable.Columns.Add("ID1")
dataTable.Columns(0).Caption = "id"
dataTable.Columns.Add("ID2")
Dim values() As Object = New Object() { "Roll Number", "Student Name" }
dataTable.Rows.Add(values)
values = New Object() { "011", "Cris" }
dataTable.Rows.Add(values)
values = New Object() { "011", "Clay" }
dataTable.Rows.Add(values)
Dim page As PdfPage = doc.Pages.Add()
Dim top As PdfPageTemplateElement = New PdfPageTemplateElement(rect)
Dim table As PdfGrid = New PdfGrid()
' Subscribe the cell layout event 
AddHandler table.BeginCellLayout, AddressOf table_BeginCellLayout
table.DataSource = dataTable
table.Style.CellPadding = 16
' Draws the table in page
table.Draw(page.Graphics)
doc.Save("Tables.pdf")
' Cell layout event handler
Private Sub table_BeginCellLayout(ByVal sender As Object, ByVal args As PdfGridBeginCellLayoutEventArgs)
  If args.RowIndex = 1 Then
     args.Graphics.DrawRectangle(New PdfPen(PdfBrushes.Red, 2), PdfBrushes.White,args.Bounds)
  End If
End Sub

CellIndex

Gets the index of the cell.

public int CellIndex { get; }

Property Value

int

Examples

// Creates a new document
PdfDocument doc = new PdfDocument();
RectangleF rect = new RectangleF(0, 0, 500, 50);
//Create DataTable for source
DataTable dataTable = new DataTable("myTable");
dataTable.Columns.Add("ID1");
dataTable.Columns[0].Caption = "id";
dataTable.Columns.Add("ID2");
object[] values = new object[] { "Roll Number", "Student Name" };
dataTable.Rows.Add(values);
values = new object[] { "011", "Cris" };
dataTable.Rows.Add(values);
values = new object[] { "011", "Clay" };
dataTable.Rows.Add(values);
PdfPage page = doc.Pages.Add();
PdfPageTemplateElement top = new PdfPageTemplateElement(rect);
PdfGrid table = new PdfGrid();
// Subscribe the cell layout event 
table.BeginCellLayout += new PdfGridBeginCellLayoutEventHandler(table_BeginCellLayout);
table.DataSource = dataTable;
table.Style.CellPadding = 16;
// Draws the table in page
table.Draw(page.Graphics);
doc.Save("Tables.pdf");
// Cell layout event handler
void table_BeginCellLayout(object sender, PdfGridBeginCellLayoutEventArgs args)
{
  if (args.RowIndex == 1)
  {
    args.Graphics.DrawRectangle(new PdfPen(PdfBrushes.Red, 2), PdfBrushes.White,args.Bounds);
  }
  //Get the cell index.
  int index = args.CellIndex;
}
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
Dim rect As RectangleF = New RectangleF(0, 0, 500, 50)
'Create DataTable for source
Dim dataTable As DataTable = New DataTable("myTable")
dataTable.Columns.Add("ID1")
dataTable.Columns(0).Caption = "id"
dataTable.Columns.Add("ID2")
Dim values() As Object = New Object() { "Roll Number", "Student Name" }
dataTable.Rows.Add(values)
values = New Object() { "011", "Cris" }
dataTable.Rows.Add(values)
values = New Object() { "011", "Clay" }
dataTable.Rows.Add(values)
Dim page As PdfPage = doc.Pages.Add()
Dim top As PdfPageTemplateElement = New PdfPageTemplateElement(rect)
Dim table As PdfGrid = New PdfGrid()
' Subscribe the cell layout event 
AddHandler table.BeginCellLayout, AddressOf table_BeginCellLayout
table.DataSource = dataTable
table.Style.CellPadding = 16
' Draws the table in page
table.Draw(page.Graphics)
doc.Save("Tables.pdf")
' Cell layout event handler
Private Sub table_BeginCellLayout(ByVal sender As Object, ByVal args As PdfGridBeginCellLayoutEventArgs)
  If args.RowIndex = 1 Then
     args.Graphics.DrawRectangle(New PdfPen(PdfBrushes.Red, 2), PdfBrushes.White,args.Bounds)
  End If
  'Get the cell index.
  Dim index As Integer = args.CellIndex
End Sub

Graphics

Gets the graphics, on which the cell should be drawn.

public PdfGraphics Graphics { get; }

Property Value

PdfGraphics

Examples

// Creates a new document
PdfDocument doc = new PdfDocument();
RectangleF rect = new RectangleF(0, 0, 500, 50);
//Create DataTable for source
DataTable dataTable = new DataTable("myTable");
dataTable.Columns.Add("ID1");
dataTable.Columns[0].Caption = "id";
dataTable.Columns.Add("ID2");
object[] values = new object[] { "Roll Number", "Student Name" };
dataTable.Rows.Add(values);
values = new object[] { "011", "Cris" };
dataTable.Rows.Add(values);
values = new object[] { "011", "Clay" };
dataTable.Rows.Add(values);
PdfPage page = doc.Pages.Add();
PdfPageTemplateElement top = new PdfPageTemplateElement(rect);
PdfGrid table = new PdfGrid();
// Subscribe the cell layout event 
table.BeginCellLayout += new PdfGridBeginCellLayoutEventHandler(table_BeginCellLayout);
table.DataSource = dataTable;
table.Style.CellPadding = 16;
// Draws the table in page
table.Draw(page.Graphics);
doc.Save("Tables.pdf");
// Cell layout event handler
void table_BeginCellLayout(object sender, PdfGridBeginCellLayoutEventArgs args)
{
  if (args.RowIndex == 1)
  {
    args.Graphics.DrawRectangle(new PdfPen(PdfBrushes.Red, 2), PdfBrushes.White,args.Bounds);
  }
}
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
Dim rect As RectangleF = New RectangleF(0, 0, 500, 50)
'Create DataTable for source
Dim dataTable As DataTable = New DataTable("myTable")
dataTable.Columns.Add("ID1")
dataTable.Columns(0).Caption = "id"
dataTable.Columns.Add("ID2")
Dim values() As Object = New Object() { "Roll Number", "Student Name" }
dataTable.Rows.Add(values)
values = New Object() { "011", "Cris" }
dataTable.Rows.Add(values)
values = New Object() { "011", "Clay" }
dataTable.Rows.Add(values)
Dim page As PdfPage = doc.Pages.Add()
Dim top As PdfPageTemplateElement = New PdfPageTemplateElement(rect)
Dim table As PdfGrid = New PdfGrid()
' Subscribe the cell layout event 
AddHandler table.BeginCellLayout, AddressOf table_BeginCellLayout
table.DataSource = dataTable
table.Style.CellPadding = 16
' Draws the table in page
table.Draw(page.Graphics)
doc.Save("Tables.pdf")
' Cell layout event handler
Private Sub table_BeginCellLayout(ByVal sender As Object, ByVal args As PdfGridBeginCellLayoutEventArgs)
  If args.RowIndex = 1 Then
     args.Graphics.DrawRectangle(New PdfPen(PdfBrushes.Red, 2), PdfBrushes.White,args.Bounds)
  End If
End Sub

IsHeaderRow

Gets the type of Grid row.

public bool IsHeaderRow { get; }

Property Value

bool

Examples

//Create a new PDF document.
PdfDocument pdfDocument = new PdfDocument();
PdfPage pdfPage = pdfDocument.Pages.Add();
//Create a new PdfGrid.
PdfGrid pdfGrid = new PdfGrid();
pdfGrid.RepeatHeader = true;
//Set properties to paginate the grid. 
pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent1);
//Add columns.
pdfGrid.Columns.Add(1);
//Add header.
pdfGrid.Headers.Add(1);
PdfGridRow pdfGridHeader = pdfGrid.Headers[0];
pdfGridHeader.Cells[0].Value = "Company";
PdfGridRow pdfGridRow;
pdfGridRow = pdfGrid.Rows.Add();
pdfGridRow.Cells[0].Value = "Syncfusion";
pdfGrid.BeginCellLayout += PdfGrid_BeginCellLayout;
PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();
layoutFormat.Break = PdfLayoutBreakType.FitPage;
layoutFormat.Layout = PdfLayoutType.Paginate;
PdfLayoutResult result = pdfGrid.Draw(pdfPage, new PointF(30, 30), layoutFormat);
//Save and close the PDF document 
pdfDocument.Save("Output.pdf");
document.Close(true);
void PdfGrid_BeginCellLayout(object sender, PdfGridBeginCellLayoutEventArgs args)
{
if (args.IsHeaderRow)
{
args.Graphics.DrawString(args.Value, new PdfStandardFont(PdfFontFamily.Helvetica, 12), PdfBrushes.Black, new PointF(10, 10));
 }
 }
Dim pdfDocument As PdfDocument = New PdfDocument
Dim pdfPage As PdfPage = pdfDocument.Pages.Add
Dim pdfGrid As PdfGrid = New PdfGrid
pdfGrid.RepeatHeader = true
'Set properties to paginate the grid. 
pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent1)
'Add columns.
pdfGrid.Columns.Add(1)
'Add header.
pdfGrid.Headers.Add(1)
Dim pdfGridHeader As PdfGridRow = pdfGrid.Headers(0)
pdfGridHeader.Cells(0).Value = "Company"
Dim pdfGridRow As PdfGridRow
pdfGridRow = pdfGrid.Rows.Add
pdfGridRow.Cells(0).Value = "Syncfusion"
pdfGrid.BeginCellLayout = (pdfGrid.BeginCellLayout + PdfGrid_BeginCellLayout)
Dim layoutFormat As PdfGridLayoutFormat = New PdfGridLayoutFormat
layoutFormat.Break = PdfLayoutBreakType.FitPage
layoutFormat.Layout = PdfLayoutType.Paginate
Dim result As PdfLayoutResult = pdfGrid.Draw(pdfPage, New PointF(30, 30), layoutFormat)
'Save and close the PDF document 
pdfDocument.Save("Output.pdf")
document.Close(true)
Private Sub PdfGrid_BeginCellLayout(ByVal sender As Object, ByVal args As PdfGridBeginCellLayoutEventArgs)
If args.IsHeaderRow Then
args.Graphics.DrawString(args.Value, New PdfStandardFont(PdfFontFamily.Helvetica, 12), PdfBrushes.Black, New PointF(10, 10))
End If
End Sub

RowIndex

Gets the index of the row.

public int RowIndex { get; }

Property Value

int

Examples

// Creates a new document
PdfDocument doc = new PdfDocument();
RectangleF rect = new RectangleF(0, 0, 500, 50);
//Create DataTable for source
DataTable dataTable = new DataTable("myTable");
dataTable.Columns.Add("ID1");
dataTable.Columns[0].Caption = "id";
dataTable.Columns.Add("ID2");
object[] values = new object[] { "Roll Number", "Student Name" };
dataTable.Rows.Add(values);
values = new object[] { "011", "Cris" };
dataTable.Rows.Add(values);
values = new object[] { "011", "Clay" };
dataTable.Rows.Add(values);
PdfPage page = doc.Pages.Add();
PdfPageTemplateElement top = new PdfPageTemplateElement(rect);
PdfGrid table = new PdfGrid();
// Subscribe the cell layout event 
table.BeginCellLayout += new PdfGridBeginCellLayoutEventHandler(table_BeginCellLayout);
table.DataSource = dataTable;
table.Style.CellPadding = 16;
// Draws the table in page
table.Draw(page.Graphics);
doc.Save("Tables.pdf");
// Cell layout event handler
void table_BeginCellLayout(object sender, PdfGridBeginCellLayoutEventArgs args)
{
  if (args.RowIndex == 1)
  {
    args.Graphics.DrawRectangle(new PdfPen(PdfBrushes.Red, 2), PdfBrushes.White,args.Bounds);
  }
}
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
Dim rect As RectangleF = New RectangleF(0, 0, 500, 50)
'Create DataTable for source
Dim dataTable As DataTable = New DataTable("myTable")
dataTable.Columns.Add("ID1")
dataTable.Columns(0).Caption = "id"
dataTable.Columns.Add("ID2")
Dim values() As Object = New Object() { "Roll Number", "Student Name" }
dataTable.Rows.Add(values)
values = New Object() { "011", "Cris" }
dataTable.Rows.Add(values)
values = New Object() { "011", "Clay" }
dataTable.Rows.Add(values)
Dim page As PdfPage = doc.Pages.Add()
Dim top As PdfPageTemplateElement = New PdfPageTemplateElement(rect)
Dim table As PdfGrid = New PdfGrid()
' Subscribe the cell layout event 
AddHandler table.BeginCellLayout, AddressOf table_BeginCellLayout
table.DataSource = dataTable
table.Style.CellPadding = 16
' Draws the table in page
table.Draw(page.Graphics)
doc.Save("Tables.pdf")
' Cell layout event handler
Private Sub table_BeginCellLayout(ByVal sender As Object, ByVal args As PdfGridBeginCellLayoutEventArgs)
  If args.RowIndex = 1 Then
     args.Graphics.DrawRectangle(New PdfPen(PdfBrushes.Red, 2), PdfBrushes.White,args.Bounds)
  End If
End Sub

Value

Gets the value.

public string Value { get; }

Property Value

string

Examples

// Creates a new document
PdfDocument doc = new PdfDocument();
RectangleF rect = new RectangleF(0, 0, 500, 50);
//Create DataTable for source
DataTable dataTable = new DataTable("myTable");
dataTable.Columns.Add("ID1");
dataTable.Columns[0].Caption = "id";
dataTable.Columns.Add("ID2");
object[] values = new object[] { "Roll Number", "Student Name" };
dataTable.Rows.Add(values);
values = new object[] { "011", "Cris" };
dataTable.Rows.Add(values);
values = new object[] { "011", "Clay" };
dataTable.Rows.Add(values);
PdfPage page = doc.Pages.Add();
PdfPageTemplateElement top = new PdfPageTemplateElement(rect);
PdfGrid table = new PdfGrid();
// Subscribe the cell layout event 
table.BeginCellLayout += new PdfGridBeginCellLayoutEventHandler(table_BeginCellLayout);
table.DataSource = dataTable;
table.Style.CellPadding = 16;
// Draws the table in page
table.Draw(page.Graphics);
doc.Save("Tables.pdf");
// Cell layout event handler
void table_BeginCellLayout(object sender, PdfGridBeginCellLayoutEventArgs args)
{
//Get the cell value.
string text = args.Value;
  if (args.RowIndex == 1)
  {
    args.Graphics.DrawRectangle(new PdfPen(PdfBrushes.Red, 2), PdfBrushes.White,args.Bounds);
  }
}
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
Dim rect As RectangleF = New RectangleF(0, 0, 500, 50)
'Create DataTable for source
Dim dataTable As DataTable = New DataTable("myTable")
dataTable.Columns.Add("ID1")
dataTable.Columns(0).Caption = "id"
dataTable.Columns.Add("ID2")
Dim values() As Object = New Object() { "Roll Number", "Student Name" }
dataTable.Rows.Add(values)
values = New Object() { "011", "Cris" }
dataTable.Rows.Add(values)
values = New Object() { "011", "Clay" }
dataTable.Rows.Add(values)
Dim page As PdfPage = doc.Pages.Add()
Dim top As PdfPageTemplateElement = New PdfPageTemplateElement(rect)
Dim table As PdfGrid = New PdfGrid()
' Subscribe the cell layout event 
AddHandler table.BeginCellLayout, AddressOf table_BeginCellLayout
table.DataSource = dataTable
table.Style.CellPadding = 16
' Draws the table in page
table.Draw(page.Graphics)
doc.Save("Tables.pdf")
' Cell layout event handler
Private Sub table_BeginCellLayout(ByVal sender As Object, ByVal args As PdfGridBeginCellLayoutEventArgs)
  'Get value
  Dim text As String = args.Value
  If args.RowIndex = 1 Then
     args.Graphics.DrawRectangle(New PdfPen(PdfBrushes.Red, 2), PdfBrushes.White,args.Bounds)        ///      
  End If
End Sub

Remarks

The value might be null or an empty string, which means that either no text were acquired or all text was on the previous page.