×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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 --> C#

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);
                }
             }
          }

          //My problem is over there      
          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());                                  
                     }
                  }
             }
          }
    }
          
} 

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

What version of Visual Studio and the Crystal SDK are you using?

-Dell

Associate Director, Data & Analytics
Protiviti
www.protiviti.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close