pass parameter value from windows form gridview checkbox to the report

Posted by: yosef.teferi on 12 April 2019, 6:31 am EST

  • Posted 12 April 2019, 6:31 am EST

    I am attempting to pass multiple values separated by comma from windows form grid view checkboxes to the Active Report and generate a pdf format report. I have my report in AppCode folder. Would you please help and show how this can be done and where I can find a sample code.

    thanks,
  • Replied 14 April 2019, 6:33 pm EST

    Hello,

    I have created the sample as per your requirement. Please refer to the attachment.
    Feel free to revert if I am missing anything.

    Thanks.
    WinformGridParameter.zip
  • Replied 15 April 2019, 5:23 am EST

    thank you for response and sample code.

    I have looked at your sample code and still have a few qeustion.

    one thing i I am working on active report section report (code based). I have built my query in private void Adver_DataInitialize(object sender, EventArgs e)

    event and trying to capture the id from the checkbox that i created in the form and pass the value to the report to generate pdf file on the fly.
    I just want user to be able run and generate a pdf report when the click the button from the form.

    I build a query in the report and also created a datagridview in the form. I just wan to see how I am able to pass for example the id of empleyee to my query i created in the section report.

    I just want to pass the Ids (1,2,3...) to the query.
  • Replied 15 April 2019, 8:04 pm EST

    Hello,

    Please refer to the modified sample for Code based report.

    Thanks.

    WinformGridParameter_modified.zip
  • Replied 18 April 2019, 3:58 am EST

    I use your sample code to get an idea as how I can manage this code to work and still not working for m.

    here is my code in the window form.
    namespace CMSPrelet
    {
    public partial class frmPrelet : Form
    {

    private void btnReport_Click(object sender, EventArgs e)

    {
    foreach (DataGridViewRow row in gvCMSPreLet.Rows)
    {
    bool isSelected = Convert.ToBoolean(row.Cells["Chk"].Value);
    if (isSelected)
    {
    // message += ",";
    message = message + row.Cells["PROPOSALNMUMBER"].Value.ToString() + ",";

    }
    }

    message = message.Trim(",".ToCharArray());
    GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport PdfExport1 = new GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport();
    CMSPreletRpt.CMSPreletRpt rpt = new CMSPreletRpt.CMSPreletRpt();
    rpt.proposalNM = message;
    rpt.Run();
    PdfExport1.Export(rpt.Document, Application.StartupPath + "\\YosefPDFExpt.pdf");


    }

    }

    }


    I am trying to pass the parameter value form the windows form button click event to Active report but the parameter value is still null even though I selected a value.

    namespace CMSPreletRpt
    {

    partial class CMSPreletRpt
    {
    private void ActiveReports_DataInitialize(object sender, EventArgs e)
    {
    string ConStr = System.Configuration.ConfigurationManager.ConnectionStrings["ConTest"].ConnectionString;

    OracleConnection oOracneConn = new OracleConnection(ConStr);

    oOracneConn.Open();
    cmdItemDetails = new OracleCommand();
    cmdItemDetails.Connection = oOracneConn;
    cmdItemDetails.CommandText = "mn_job_Test";
    cmdItemDetails.CommandType = CommandType.StoredProcedure;
    cmdItemDetails.Parameters.Add(new OracleParameter("P_Proposal_Id", OracleDbType.Varchar2)).Value = proposalNM;
    cmdItemDetails.Parameters.Add(new OracleParameter("p_result", OracleDbType.RefCursor)).Direction = ParameterDirection.Output;
    drItemDetails = cmdItemDetails.ExecuteReader();
    this.DataSource = drItemDetails;

    }

    private void ActiveReports_ReportStart(object sender, EventArgs e)
    {

    txtPubDate11.DataField = "PDate";
    txtLetDate111.DataField = "LDate";
    txtContId111.DataField = "PNum";
    txtSPNum.DataField = "Sp";
    txtDBE11.DataField = "Dbe";
    txtItem11.DataField = "ADDDESCRIPTION";
    txtWJR11.DataField = "LDesc";

    txtTimeAndDate11.Text = System.DateTime.Now.ToString();
    }

    }

    }

  • Replied 21 April 2019, 7:27 pm EST

    Hello Yosef!

    Please refer to the "To use an Unbound Data source" topic in the following link to achieve your requirements. You need to add fields in the "DataInitialize" event and set the data in Fields in "FetchData" event.
    https://help.grapecity.com/activereports/webhelp/AR13/webframe.html#BindReportstoaDataSource.html

    Hope it helps.

    Thanks.
  • Replied 22 April 2019, 1:49 am EST

    thanks for the reply. I have reviewed the code and did not see a way to pass parameter value from the windows form to the report. that is my only problem.
  • Replied 22 April 2019, 12:55 pm EST

    I was able to pass the parameter value from windows form to the report now. I am still not able to figure out how to create a pdf file on the fly. I want the user to be able create a pdf file without saving the file.
  • Replied 22 April 2019, 7:24 pm EST

    Hello Yosef,

    I am glad that your parameter issue is resolved now. You can use the following line of code to create a pdf file on the fly:

    System.IO.MemoryStream m_stream = new System.IO.MemoryStream();
    SectionReport rpt = new SectionReport();
    rpt.Run();
    this.PdfExport1.Export(rpt.Document, m_stream);
    m_stream.Position = 0;
    Response.ContentType = "application/pdf";
    Response.BinaryWrite(m_stream.ToArray());
    Response.End();


    Hope it helps

    Thanks
  • Replied 22 April 2019, 10:42 pm EST

    Hello,

    I do not think I can use this code as this is a windows application. I get Response does not exist in the current context error.

    this.PdfExport1.Export(rpt.Document, m_stream);
    m_stream.Position = 0;
    Response.ContentType = "application/pdf";
    Response.BinaryWrite(m_stream.ToArray());
    Response.End();
  • Replied 23 April 2019, 8:17 pm EST

    Hello,

    You can save the PDF in the memory stream with the following code and you can use the Memory stream according to your case.

    System.IO.MemoryStream m_stream = new System.IO.MemoryStream();
    SectionReport rpt = new SectionReport();
    rpt.Run();
    this.PdfExport1.Export(rpt.Document, m_stream);


    Please explain If I am missing something.

    Thanks.

  • Replied 24 April 2019, 2:15 am EST

    Hello thanks for the response. I am not sure what change that I need to make to produce pdf on the fly. this code does not produce that. please let me know if you see issue with this code.

    private void btnReport_Click(object sender, EventArgs e)

    {
    foreach (DataGridViewRow row in gvCMSPreLet.Rows)
    {
    bool isSelected = Convert.ToBoolean(row.Cells["Chk"].Value);
    if (isSelected)
    {
    // message += ",";
    message = message + row.Cells["PROPOSALNMUMBER"].Value.ToString() + ",";

    }
    }

    message = message.Trim(",".ToCharArray());

    GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport PdfExport1 = new GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport();

    System.IO.MemoryStream m_stream = new System.IO.MemoryStream();
    CMSPreletRpt.CMSPreletRpt rpt = new CMSPreletRpt.CMSPreletRpt();
    rpt.proposalNM = message;
    rpt.Run();
    PdfExport1.Export(rpt.Document, m_stream);





    }




  • Replied 24 April 2019, 7:25 pm EST

    Hello Yosef,

    >> I want the user to be able create a pdf file without saving the file.
    Could you please clarify on what do you mean by this. What I understand from this, you don't want to save the generated PDF in the file. That's why I provide you the memory stream code to save the pdf in the memory stream.
    Do you want to show the generated PDF document in a viewer? Could you please explain your requirements.

    Thanks.
  • Replied 25 April 2019, 4:12 am EST

    Sorry for not being clear on my requirements. Yes, what I want is for the user to be able view the pdf file on the fly when they click the button. yes, I want to show the generated pdf document in a viewer. I appreciate if you have a sample code that shows that.

    thanks,
  • Marked as Answer

    Replied 25 April 2019, 5:07 pm EST

    Hello,

    AR Viewer does not have a feature to view PDF file. You need to use another component to view the PDF File. I would recommend you to use the C1FLexViewer and C1PdfDocumentSource to view the PDF report. Please refer to the following documentation link to know more about them:

    https://www.grapecity.com/en/flexviewer
    https://help.grapecity.com/componentone/NetHelp/C1Document/webframe.html#PDFDocumentSource-Quick-Start.html
    https://help.grapecity.com/componentone/NetHelp/C1Document/C1.Win.C1Document.4~C1.Win.C1Document.C1PdfDocumentSource~LoadFromStream.html

    Thanks.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels