question

KwebenaAcquah-9104 avatar image
0 Votes"
KwebenaAcquah-9104 asked TimonYang-MSFT commented

how to stop replication of row in rdlc report

I am having a datagrid called dgvRESULTPRINTER like this;
87182-captuyre.png

each time a column is selected and a button is clicked my data show up on a report like this using this code

87211-87172-captudddeuu.png

my button1 click event to show each selected column

 DataTable dtRep = ((DataView)dgvRESULTPRINTER.ItemsSource).Table.Clone();
             for (int i = 0; i < dgvRESULTPRINTER.SelectedItems.Count; i++)
             {
                 dtRep.ImportRow(((DataRowView)dgvRESULTPRINTER.SelectedItems[i]).Row);
             }
             dtRep.AcceptChanges();
             TermlyReportShower tps = new TermlyReportShower();
             tps.ShowDialog();


now my problems is that each time a row is selected on the datagrid above and my button1 is clicked i keep getting a replication of each row showing in my report; like this
87174-captuddtde.jpg


Update
this the loaded event of my termly report shower
am using a usercontrol that loads the report and a window(called termlyreportshower) loads the usercontrol am using wpf

   private void UserControl_Loaded(object sender, RoutedEventArgs e)
         {
             SqlConnection con = new SqlConnection(shoolmanangmentconn);
             SqlDataAdapter dataAdapter = new SqlDataAdapter("SELECT Math, English FROM tbl_TestingThatSubjects", con);
             DataSet ds = new DataSet();
             dataAdapter.Fill(ds);
             reportViewer.Reset();
             this.reportViewer.LocalReport.DataSources.Clear();
             ReportDataSource reportDataSource = new ReportDataSource();
             reportDataSource.Value = ds.Tables[0];
             reportDataSource.Name = "DataSet1";
             reportViewer.LocalReport.ReportPath = "C:\\Users\\hp\\source\\repos\\SMSKICSO\\SMSKICSO\\myReports\\TermlyReport.rdlc";
             reportViewer.LocalReport.DataSources.Add(reportDataSource);
             reportViewer.RefreshReport();
         }
         private void reportViewer_RenderingComplete(object sender, Microsoft.Reporting.WinForms.RenderingCompleteEventArgs e)    
         {
         }

BUT i only want to show just one row as selected;
please can some one help me fixe this problem (perhaps its from my code on button1 click)




dotnet-csharpwindows-wpf
captuyre.png (3.1 KiB)
captuddtde.jpg (50.0 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@KwebenaAcquah-9104
I am trying to solve this problem and it will take some time.
Please wait a moment and thank you for your understanding.

0 Votes 0 ·

thanks Sir, Waiting, Counting On your Teachings ;

0 Votes 0 ·

1 Answer

TimonYang-MSFT avatar image
0 Votes"
TimonYang-MSFT answered TimonYang-MSFT commented

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?

88398-1.png

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.

88399-2.png

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.


1.png (19.3 KiB)
2.png (14.8 KiB)
· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

please sir i just updated the question (thanks)

0 Votes 0 ·

@KwebenaAcquah-9104
I updated the answer, please check if it can solve your problem.

0 Votes 0 ·

that didn't work sir

0 Votes 0 ·
Show more comments