|
PdfExportingOptions options = new PdfExportingOptions();
options.CellExporting += cellExporting;
var document = sfDataGrid.ExportToPdf(options);
document.Save("Sample.pdf");
private void cellExporting(object sender, DataGridCellPdfExportingEventArgs e)
{
if (e.CellType == ExportCellType.RecordCell && e.ColumnName == "OrderID")
{
var style = new PdfGridCellStyle();
PdfPen normalBorder = new PdfPen(PdfBrushes.DarkGray, 0.2f);
System.Drawing.Image image = null;
if (Convert.ToInt16(e.CellValue) % 2 == 0)
image = SystemIcons.Information.ToBitmap();
else
image = SystemIcons.Shield.ToBitmap();
style.BackgroundImage = PdfImage.FromImage(image);
e.PdfGridCell.ImagePosition = PdfGridImagePosition.Center;
e.PdfGridCell.Style = style;
e.PdfGridCell.Style.Borders.All = normalBorder;
e.CellValue = string.Empty;
}
} |
|
DataTable table = GetDataTable();
sfDataGrid1.AutoGenerateColumns = false;
sfDataGrid1.Columns.Add(new GridNumericColumn() { MappingName = "OrderID" });
sfDataGrid1.Columns.Add(new GridTextColumn() { MappingName = "CustomerID" });
sfDataGrid1.Columns.Add(new GridTextColumn() { MappingName = "CustomerName" });
sfDataGrid1.Columns.Add(new GridTextColumn() { MappingName = "Country" });
sfDataGrid1.Columns.Add(new GridImageColumn() { MappingName = "Flag", ImageLayout = ImageLayout.Stretch });
sfDataGrid1.DataSource = table;
sfDataGrid1.QueryImageCellStyle += SfDataGrid1_QueryImageCellStyle; private void SfDataGrid1_QueryImageCellStyle(object sender, Syncfusion.WinForms.DataGrid.Events.QueryImageCellStyleEventArgs e) {
var employee = (DataRowView)e.Record;
e.Image = (Image.FromFile(@"..\..\Image\"+ employee.Row.ItemArray[3].ToString()+".png"));
} |
|
DataTable table = GetDataTable();
sfDataGrid1.AutoGenerateColumns = false;
sfDataGrid1.Columns.Add(new GridNumericColumn() { MappingName = "OrderID" });
sfDataGrid1.Columns.Add(new GridTextColumn() { MappingName = "CustomerID" });
sfDataGrid1.Columns.Add(new GridImageColumn() { MappingName = "Flag", ImageLayout = ImageLayout.Stretch });
sfDataGrid1.Columns.Add(new GridTextColumn() { MappingName = "CustomerName" });
sfDataGrid1.Columns.Add(new GridTextColumn() { MappingName = "Country" });
sfDataGrid1.QueryImageCellStyle += SfDataGrid1_QueryImageCellStyle;
sfDataGrid1.DataSource = table; |
|
sfDataGrid1.Columns.Add(new GridImageColumn() { MappingName = "Flag", ImageLayout = ImageLayout.Zoom });
|
|
// Set the RowHeight
sfDataGrid1.RowHeight = 150;
// set the TableSummaryRow height sfDataGrid1.QueryRowHeight += SfDataGrid1_QueryRowHeight;
private void SfDataGrid1_QueryRowHeight(object sender, Syncfusion.WinForms.DataGrid.Events.QueryRowHeightEventArgs e) {
if (sfDataGrid1.TableControl.IsTableSummaryIndex(e.RowIndex))
{
e.Height = 30;
e.Handled = true;
}
} |