I reproduced the problem, it has nothing to do with the code in the button click event.
When you created a report, did you add some blank lines like the following?
These blank lines are the cause of the problem, and the number of blank lines between the result report data is the number of blank lines here.
Try to delete all blank lines and keep only the first necessary line.
Update:
In the above code, you find all the data from the database and fill it into the report every time you load the usercontrol, but according to your latest comment, this does not seem to meet your requirements.
According to your description, we can add a constructor to TermlyReportShower, take the datatable in the button1 click event as a parameter, and then fill this table into the report.
private void button_Click(object sender, RoutedEventArgs e)
{
DataTable dtRep = ((DataView)dataGrid.ItemsSource).Table.Clone();
for (int i = 0; i < dataGrid.SelectedItems.Count; i++)
{
dtRep.ImportRow(((DataRowView)dataGrid.SelectedItems[i]).Row);
}
dtRep.AcceptChanges();
TermlyReportShower window1 = new TermlyReportShower(dtRep);
window1.ShowDialog();
}
In TermlyReportShower window:
public TermlyReportShower(DataTable dataTable)
{
InitializeComponent();
ReportViewer reportViewer1 = new ReportViewer();
ReportDataSource reportDataSource = new ReportDataSource();
reportDataSource.Value = dataTable;
reportDataSource.Name = "DataSet1";
reportViewer1.LocalReport.ReportPath = @"D:\VsWorkSpace\4_16\WindowsFormsApp1\Report1.rdlc";
reportViewer1.LocalReport.DataSources.Add(reportDataSource);
reportViewer1.RefreshReport();
windowsFormsHost.Child = reportViewer1;
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.