Код: Выделить всё
private void btnPrint_Click(object sender, RoutedEventArgs e){
try
{
var clientList = dataGridClients.ItemsSource
.Cast()
.ToList();
if (clientList == null || clientList.Count == 0)
{
MessageBox.Show("No data available for printing.");
return;
}
Report report = new Report();
report.Load(@"reports\client_list.frx");
// Register the memory list as a DataSource
report.RegisterData(clientList, "Clients");
report.GetDataSource("Clients").Enabled = true;
// Bind the existing DataBand to the DataSource
var dataBand = report.FindObject("DataBand1") as FastReport.DataBand;
if (dataBand != null)
{
dataBand.DataSource = report.GetDataSource("Clients");
}
else
{
MessageBox.Show("DataBand1 not found in the report.");
return;
}
// Prepare and show the report
report.Prepare();
string tempPdfPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), $"report_{Guid.NewGuid()}.pdf");
report.Export(new PDFSimpleExport(), tempPdfPath);
Process.Start(new ProcessStartInfo
{
FileName = tempPdfPath,
UseShellExecute = true
});
}catch (Exception ex)
{
MessageBox.Show("Printing error: " + ex.Message);
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... ort-commun