how to stop replication of row in rdlc report

KwebenaAcquah-9104 306 Reputation points
2021-04-13T00:42:13.48+00:00

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)

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,686 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,364 questions
{count} votes

Accepted answer
  1. Timon Yang-MSFT 9,576 Reputation points
    2021-04-14T08:45:16.263+00:00

    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.


0 additional answers

Sort by: Most helpful