Sending DataGridview Date to Fastreport.net in C#

Hi


I wrote a program with C # and used Fast Report for reports.

The problem I have is send the information in the grid view or data table to fast report.

Can you help me ?

Comments

  • show the code...

  • i have a datagridview in my program and i want to display the information of that in Data Section in my report

    My Code in C#:

          //******* Create Data Table And Fill With Data From Datagrid view *******************

          DataTable dtPrint = new DataTable();

          dtPrint.Columns.Add("StockName");

          dtPrint.Columns.Add("Weight");

          dtPrint.Columns.Add("Amount");

          dtPrint.Columns.Add("Price");

          foreach(DataGridViewRow item in dataGridView1.Rows)

          {

            dtPrint.Rows.Add(

               item.Cells[1].Value.ToString()

              ,item.Cells[2].Value.ToString()

              ,item.Cells[3].Value.ToString()

              ,item.Cells[4].Value.ToString()

              );

          }

          //***************************Set Fast Report Parameter************************************

          report1.Load("Untitled.frx");

          report1.SetParameterValue("timePara", TimeLabel.Text);

          report1.SetParameterValue("DatePara", DateLabel.Text);

          report1.SetParameterValue("NumPara", NumLabel.Text);

          report1.SetParameterValue("NamePara", NameTextBox.Text);

          report1.SetParameterValue("DocDatePara", DocDate.Text);

          report1.SetParameterValue("DocNumPara", DocNumTextBox.Text);

          report1.SetParameterValue("TWeightPara", TotalWeightLabel.Text);

          report1.SetParameterValue("TAmountPara", TotalWeightLabel.Text);

          //report1.RegisterData(dtPrint,"DT");

          report1.Prepare();

          report1.ShowPrepared(); 

  • your code seems right to me, please attach untitled.frx

  • unfortunately, I could not upload the file here. i emailed it to you.

    My problem is defining a data source without connecting to the database

  • yes, your problem is how to define datasource, try this:

        report1.Load("Untitled.frx");

          report1.SetParameterValue("timePara", TimeLabel.Text);

          report1.SetParameterValue("DatePara", DateLabel.Text);

          report1.SetParameterValue("NumPara", NumLabel.Text);

          report1.SetParameterValue("NamePara", NameTextBox.Text);

          report1.SetParameterValue("DocDatePara", DocDate.Text);

          report1.SetParameterValue("DocNumPara", DocNumTextBox.Text);

          report1.SetParameterValue("TWeightPara", TotalWeightLabel.Text);

          report1.SetParameterValue("TAmountPara", TotalWeightLabel.Text);

          report1.RegisterData(dtPrint,"DT");

    // open the designer

    report.Design();

    // uncomment below if you already done your report design

          //report1.Prepare();

          //report1.ShowPrepared(); 


  • sorry, it should be: report1.Design(); 😀

  • Wowww

    Thanks, the problem is solved.

    Can you just explain how DT is defined in "Untitled.frx" ?

  • open untitled.frx with notepad. if you know the data fields, you may add/modify yourself and after adding tabledatasource, you can edit the report without data.

    report.design(); => push data from application to fastreport and open the designer


      <TableDataSource Name="DT" ReferenceName="DT" DataType="System.Int32" Enabled="true">

       <Column Name="StockName" DataType="System.String"/>

       <Column Name="Weight" DataType="System.String"/>

       <Column Name="Amount" DataType="System.String"/>

       <Column Name="Price" DataType="System.String"/>

      </TableDataSource>


    note: <tabledatasource> is for datatable/dataset

    <BusinessObjectDataSource> is for businessobject

  • Thanks ipong

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.