Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.


What I have tried:

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

<pre lang="C#"><pre>
        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)


my error is shown on this image link;

https://i.stack.imgur.com/Pgj84.png
Posted
Updated 2-Apr-21 22:57pm
v3
Comments
[no name] 2-Apr-21 1:20am    
You need to step through it; and specify what "doesn't work"? The clone? The import? Don't know?

1 solution

Try this:

<prelang="c#">((DataTable)dgv.DataSource.ToTable()).Clone();

Personally, I would never work directly with a DataTable. All of my database stuff is handled through a DAL and is moved to/from model entities.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900