C#2015 Winform Datagrid视图将选定的行添加到rdlc报表 [英] C# 2015 winform datagrid view selected rows to rdlc report
问题描述
我是Windows应用程序和C#的新手。我将 C#2015
用于 windows应用程序
和 MS-Access 2007
数据库。
I am novice to windows application and C#. I am using C# 2015
for a windows application
with MS-Access 2007
database.
我已经使用表单完成了CRUD操作,并在 datagridview
中显示了记录,似乎可以正常工作精细。
I have completed CRUD operations using form and display that records in a datagridview
, seems working fine.
现在,我要显示的是 gridview $ c中选择的
行
$ c>生成报告并打印。另外,我不希望它们显示为表格,而是每个记录的表格。这样,如果选择了3行,则每行将打印3页。
Now, what I want is display the selected rows
of gridview
into a report and print it. Also I don't want them to be display as a table but a form for each records. So that if 3 rows are selected then there will be 3 pages to be printed for each row.
我完成的代码如下:
customer.cs
namespace bolt
{
class customer
{
public int? id { get; set; }
public string firstName { get; set; }
public string middleName { get; set; }
public string lastName { get; set; }
public string panNo { get; set; }
public string email { get; set; }
public string mobile { get; set; }
public string address { get; set; }
public int dptype { get; set; }
public string benificiaryId { get; set; }
public string bankName { get; set; }
public string bankBranch { get; set; }
public string bankAccountNo { get; set; }
customer(int? id = null, string firstName = null, string middleName = null, string lastName = null,
string panNo = null, string email = null, string mobile = null, string address = null, int dptype = 1,
string benificiaryId = null, string bankName = null, string bankBranch = null, string bankAccountNo = null
)
{
this.id = null;
this.firstName = firstName;
this.middleName = middleName;
this.lastName = lastName;
this.panNo = panNo;
this.email = email;
this.mobile = mobile;
this.address = address;
this.dptype = dptype;
this.benificiaryId = benificiaryId;
this.bankName = bankName;
this.bankBranch = bankBranch;
this.bankAccountNo = bankAccountNo;
}
public customer()
{
}
}
}
在其中添加了表单 frmReport
和 reportviewer
。
Added a form frmReport
and reportviewer
inside that.
添加了一个包含 datagridview
的表单 frmCustomer
。
Added a form frmCustomer
which contains datagridview
.
添加了 rdlc
报告 rptBolt.rdlc
尚未在其中添加任何控件。
Added a rdlc
report rptBolt.rdlc
, I have not added any control inside it.
在 frmCustomer
中,我有一个打印按钮。单击它后,以下代码
In frmCustomer
, I have a print button. On clicking it the following code
private void btnPrint_Click(object sender, EventArgs e)
{
List<customer> lstCustomer = new List<customer>();
foreach(DataGridViewRow row in dgCustomers.SelectedRows)
{
customer c = new customer();
c.id = Convert.ToInt32(row.Cells[dgCustomers.Columns["Id"].Index].Value);
lstCustomer.Add(c);
}
frmReport r = new frmReport();
r.Show();
ReportViewer v = r.Controls.Find("reportViewer1", true).FirstOrDefault() as ReportViewer;
ReportDataSource dataset = new ReportDataSource("boltReport", lstCustomer);
v.LocalReport.ReportEmbeddedResource = "bolt.rptBolt.rdlc";
v.LocalReport.DataSources.Clear();
v.LocalReport.DataSources.Add(dataset);
v.LocalReport.Refresh();
dataset.Value = lstCustomer;
v.LocalReport.Refresh();
this.Hide();
}
我丢了很多教程,但每个教程都使用报告向导和数据集直接连接到数据库的文件,以我为例,我使用的是列表。
I have gone throw many tutorials but each of them are using report wizard and dataset that are directly connected to database, in my case I am using a list.
让我知道我是在错误的道路上还是应该做什么?您可以提供答案,或者至少提供一个我可以得到我想要的链接。
Let me know if am I on the wrong path or what should I do for it? You may provide answer or at least a link that I may get what I want.
推荐答案
不需要所有这些代码
只需在目标表或select语句
中添加一列并为其分配值,例如 RSelected = 1
更新值以保存Re选择为1,然后您必须将其赋值为0或所需的任何值
,然后可以在SQL语句
的代码中选择此值)))) ))
No need to all this code
you just add a column in your aim table or in your select statement
and assign a value to it for example RSelected =1
just make update value to save Re selected to 1 and you have to assign after that to 0 or what ever value you need ,
then you can select this value in your code in SQL statement
that's it ))))))
这篇关于C#2015 Winform Datagrid视图将选定的行添加到rdlc报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!