首页 > 解决方案 > how to use the foreach loop to pass each row of a wpf datagridview with Thesame data source as a report back to the report

问题描述

how can i bind my report/report Viewer to a datagrid view with the Data source as that of the report dataset? ive created an ID card design in a Report. I bind all textbox in the report in my database fields(Data set). but when i run the program, the reportViewer only displays the data from the first rowof my database.

Now, I want to bind my report to a datagrid so i can control which row i am going to display in the reportViewer.

i have search the internet so far this is what i found;

DataTable dtRep = ((DataTable)dgv.DataSource).Clone();
        foreach (DataGridViewRow row in dgv.SelectedRows)
        {
            dtRep.ImportRow(((DataTable)dgv.DataSource).Rows[row.Index]);
        }
        dtRep.AcceptChanges();

but this doesn't work in wpf can some one help me with a code that could help me accomplish this? (thanks)

UPDATE am very sorry i run out of credit while uploading the question please pardon my ignorance;

HERE IS the image of my error from my code;

DataTable dtRep = ((DataTable)dgvRESULTPRINTER.ItemsSource).Clone();
    foreach (DataGridViewRow row in dgvRESULTPRINTER.SelectedItems)
    {
        dtRep.ImportRow(((DataTable)dgvRESULTPRINTER.DataSource).Rows[row.Index]);
    }
    dtRep.AcceptChanges();

enter image description here

标签: c#wpfdatagridview

解决方案



推荐阅读