Hi,
I have a working code below that transfers data from a dataGridView to a Crystal Report using a dataset. Am using for loop to loop through dataGridView Rows. Problem is that when i have too much data on the dataGridView, and i run this code, i experience a flickering effect and it takes such a long time to finish populating the report. My quess is that, that happens because of the for loop. Is there a way i can transfer the data to crystal report without using a for loop or maybe a better solution to my flickering and time taken problem??
Thanks in advance for any help granted.
Here is my code
DataSet4 ds = new DataSet4();
DataTable t = ds.Tables.Add("stock");
t.Columns.Add("Item_Name", Type.GetType("System.String"));
t.Columns.Add("Store", Type.GetType("System.String"));
t.Columns.Add("Total_Stock", Type.GetType("System.String"));
t.Columns.Add("Product_Code", Type.GetType("System.String"));
DataRow r;
string ItemName = string.Empty;
string sto = string.Empty;
string totostok = string.Empty;
string pcode = string.Empty;
for (int i = 0; i < dataGridView1.RowCount; i++)
{
pcode = dataGridView1.Rows[i].Cells[0].Value.ToString();
ItemName = dataGridView1.Rows[i].Cells[1].Value.ToString();
sto = dataGridView1.Rows[i].Cells[2].Value.ToString();
totostok = dataGridView1.Rows[i].Cells[3].Value.ToString();
r = t.NewRow();
r["Product_Code"] = pcode;
r["Item_Name"] = ItemName;
r["Store"] = sto;
r["Total_Stock"] = totostok;
t.Rows.Add(r);
CrystalReport4 objRpt = new CrystalReport4();
objRpt.SetDataSource(ds.Tables[1]);
crystalReportViewer1.ReportSource = objRpt;
crystalReportViewer1.Dock = DockStyle.Fill;
crystalReportViewer1.Refresh();
crystalReportViewer1.Show();
}