Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crystal report doesn't display all records of the datagridview but olny the last one.

Status
Not open for further replies.

WomanPro

Programmer
Nov 1, 2012
180
0
0
GR
I have created a back - end application in C# with embedded microsft sql server. I am pretty new to crystal reports and I had created one but in a wrong way and I am trying to correct it. I almost don't remember how I created and I feel bad for that.

So, I have a form represent orders management. So when the user runs the application, he enters an OrderID in the Search Text Box and the corresponding Order appears in the form controls. More detailed, the displayed Order comes with the appropriate Invoice Record, the appropriate Customer that made this order, all these appear in RichTextBoxes, and a DataGridView that displays the products that Customer ordered. Everything runs perfectly. So, I have multiple queries executed at runtime in order to get the appriate data.

I also have button for my crystal report of the searched order, the btnPrint.
I would like also to mention that report values are place to details section.

The problem comes when I try to give values to the report from the DataGridView with GiveValuesToRpt function, all the other values appears correctly. I get to the Report only the last record of product details of the DataGridView and not all the records it's need. What can I do? Any suggestions, help and explanation will be much appreciated.
My crystal report is being created through Visual Studio, in C#.

Here is my source code with no effect:

Code:
private void btnPrint_Click(object sender, EventArgs e)
{
   Reports.OrderRpt orderRprt = new Reports.OrderRpt(); ;
            
   OrdersPrintReport printFrm = new OrdersPrintReport(ref orderRprt);

   IEnumerable<String> paramNames = (from CrystalDecisions.Shared.ParameterField p in orderRprt.ParameterFields

                                              where string.IsNullOrEmpty(p.ReportName)

                                              select p.Name);


   foreach (Control Container in this.Controls)
     if (Container.GetType() == typeof(GroupBox) || Container.GetType() == typeof(Panel))
     {
         GiveValuesToRpt(Container, paramNames,ref orderRprt);
     }

   printFrm.Text = this.Text;
   fromForm.OpenChildForm(printFrm, this.fromForm.menuBtn);
}

private void GiveValuesToRpt(Control Container, IEnumerable<String> paramNames, ref Reports.OrderRpt OrderReport)
{
    IEnumerable<RichTextBox> RtBoxes;
    IEnumerable<CustomCombo> Cbos;
    IEnumerable<CheckBox> checkBoxes;

    IEnumerable<DateTimePicker> dtPickers;
    dtPickers  = Enumerable.Empty<DateTimePicker>();
    IEnumerable<DataGridView> dtGridViews;


    string name, ColumnName;//, strValue;
            
    RtBoxes = SaveSQLquery.GetControls<RichTextBox>(Container.Controls);
    Cbos = SaveSQLquery.GetControls<CustomCombo>(Container.Controls);
    dtPickers = SaveSQLquery.GetControls<DateTimePicker>(Container.Controls);
    checkBoxes = SaveSQLquery.GetControls<CheckBox>(Container.Controls);
    dtGridViews = SaveSQLquery.GetControls<DataGridView>(Container.Controls);

    foreach (Control cntrl in Container.Controls)
    {
        if (RtBoxes.Any())
          foreach (var RTxtbox in RtBoxes)
          {
             if (paramNames.Contains(RTxtbox.Name))
             {
                name = RTxtbox.Name.ToString();
                OrderReport.SetParameterValue(name, RTxtbox.Text);
             }
          }
          if (Cbos.Any())
             foreach (var Cbo in Cbos)
             {
                 if (paramNames.Contains(Cbo.Name))
                     OrderReport.SetParameterValue(Cbo.Name, Cbo.Text);
             }
          if (dtPickers.Any())
             foreach (var dtP in dtPickers)
             {
                if (paramNames.Contains(dtP.Name))
                {
                   OrderReport.SetParameterValue(dtP.Name, DateTime.Parse(dtP.Text.ToString()));
                }
             }
          if (checkBoxes.Any())
          {
             foreach (var checkBox in checkBoxes)
             {
                if (paramNames.Contains(checkBox.Name))
                {
                   bool value = checkBox.Checked;
                   string yes = "Ναι";

                   if (!value) yes = "Όχι";

                   OrderReport.SetParameterValue(checkBox.Name, yes);
                }
             }
          }

          //[b][COLOR=#EF2929]My problem is over there[/color][/b]      
          if (dtGridViews.Any())
          {
             foreach (var dtGridV in dtGridViews)
             {
                for (int iR = 0; iR <= dtGridV.Rows.Count - 1; iR++)
                  for (int iC = 0; iC <= dtGridV.Columns.Count - 1; iC++)
                  {
                     ColumnName = dtGridV.Columns[iC].Name;
                     if (paramNames.Contains(ColumnName))
                     {
                        if (dtGridV.Rows[iR].Cells[ColumnName].Value.GetType() == typeof(string))
                            OrderReport.SetParameterValue(ColumnName, dtGridV.Rows[iR].Cells[ColumnName].Value.ToString());                                  
                     }
                  }
             }
          }
    }
          
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top