Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have two datagridviews with different rows counts.i want to add them in to one crystal report.
this is my report http://i.imgur.com/2ixrXBr.png

i want out put like this.http://i.imgur.com/8e6T635.jpg[^]

What I have tried:

private void button1_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Total", typeof(string));
foreach (DataGridViewRow dgr in dataGridView1.Rows)
{
dt.Rows.Add(dgr.Cells[0].Value, dgr.Cells[1].Value);
}

ds.Tables.Add(dt);
ds.WriteXmlSchema("testdata.xml");
//-----------------------------------------------------------
DataSet ds1 = new DataSet();
DataTable dt1 = new DataTable();
dt1.Columns.Add("Name", typeof(string));
dt1.Columns.Add("Product", typeof(string));
dt1.Columns.Add("Qty", typeof(string));
foreach (DataGridViewRow dgr1 in dataGridView2.Rows)
{
dt1.Rows.Add(dgr1.Cells[0].Value, dgr1.Cells[1].Value ,dgr1.Cells[2].Value);
}
ds1.Tables.Add(dt1);
ds1.WriteXmlSchema("dxdx.xml");

//------------------------
ReportDocument report = new paysheet();
report.Database.Tables[0].SetDataSource(dt);
report.Database.Tables[1].SetDataSource(dt1);
crystalReportViewer1.ReportSource = report;

}
Posted
Updated 28-Jul-16 21:33pm
v3

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