2 posts, 0 answers
  1. fazera
    fazera avatar
    3 posts
    Member since:
    Jan 2020

    Posted 28 Jan Link to this post

    Hi, currently I'm create table report programmatically. Here I attach the code for generate the report in <report>. Then I call the report in user control form. In the user control form, I create the filter button "proceed". Then I do the filter in the UC form and I pass the filter in the GetData() function in <report>. The problem is the parameter value is reset then it will generate the report before filter. The parameter value I set in User control form <ucReport>. The picture shows that I have done filter the search by date from 1/1/2020 - 15/1/2020. But the table not filter. 


    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    using Telerik.Reporting;
    using Telerik.Reporting.Drawing;
    using Telerik.Reporting.Charting;
    using Telerik.Reporting.Processing;
    using MYScanLibrary;
    using System.Data;

    namespace MYScanDesktop

        /// <summary>
        /// Summary description for Report2.
        /// </summary>
        public partial class jkdmReport1 : Telerik.Reporting.Report
            System.ComponentModel.BindingList<Entry> ReportEntry;

            // private List<Graph> GraphData;
            private string testfilter = "";
            public jkdmReport1()
                // Required for telerik Reporting designer support
                ReportEntry = new System.ComponentModel.BindingList<Entry>();
                // TODO: Add any constructor code after InitializeComponent call

            public void setFilter(String f)
                testfilter = f;
               MessageBox.Show("testfilter1: " + testfilter);

            public String getFilter()
                return testfilter;

            public DataTable GetData()
                //String filter = a;
                dynamic table = new DataTable();

               // this.StartDate.Value = "= Parameters.StartDate.Value";
                int myentry = Program.myScanDB.queryEntry(ReportEntry, testfilter);
                table.Columns.Add("ID", typeof(string));
                table.Columns.Add("DateTime", typeof(string));
                table.Columns.Add("Gate", typeof(string));
                table.Columns.Add("Lane", typeof(string));
                table.Columns.Add("LPN", typeof(string));
                table.Columns.Add("BackLPN", typeof(string));
                table.Columns.Add("ContainerNo", typeof(string));
                table.Columns.Add("BackContainerNo", typeof(string));
                table.Columns.Add("WIM", typeof(string));
                table.Columns.Add("WIMDoc", typeof(string));
                table.Columns.Add("Wheel Base", typeof(string));
                table.Columns.Add("RM", typeof(string));
                table.Columns.Add("Status", typeof(string));

                for (int i = 0; i < myentry; i++)
                    //add data rows value in each column

                return table;

            public void GenerateReport()
                //create a blank Table item
                Telerik.Reporting.Table table1 = new Telerik.Reporting.Table();
                table1.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Inch(0.6), Telerik.Reporting.Drawing.Unit.Inch(0.6));
                table1.Name = "Table1";
                table1.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(4), Telerik.Reporting.Drawing.Unit.Inch(1));

                //get the data for the table
                DataTable data = GetData();
                table1.DataSource = data;

                //create a dynamic row group
                Telerik.Reporting.TableGroup DetailRowGroup = new Telerik.Reporting.TableGroup();
                DetailRowGroup.Groupings.Add(new Telerik.Reporting.Grouping(null));
                DetailRowGroup.Name = "DetailRowGroup";
                //add a row container
                table1.Body.Rows.Add(new Telerik.Reporting.TableBodyRow(Telerik.Reporting.Drawing.Unit.Inch(0.5)));
                table1.ColumnHeadersPrintOnEveryPage = true;
                table1.RowHeadersPrintOnEveryPage = true;

                //add columns
                for (int i = 0; i <= data.Columns.Count - 1; i++)
                    //add a column container
                    table1.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(Telerik.Reporting.Drawing.Unit.Inch(2)));
                    //add a static column group per data field
                    Telerik.Reporting.TableGroup columnGroup = new Telerik.Reporting.TableGroup();

                    //header textbox
                    Telerik.Reporting.TextBox headerTextBox = new Telerik.Reporting.TextBox();
                    headerTextBox.Name = "headerTextBox" + i.ToString();
                    headerTextBox.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(0.571D), Telerik.Reporting.Drawing.Unit.Inch(0.533D));
                    headerTextBox.Value = data.Columns[i].ColumnName;
                    headerTextBox.Style.BackgroundColor = System.Drawing.SystemColors.HotTrack;
                    headerTextBox.Style.Color = System.Drawing.Color.White;
                    headerTextBox.Style.Font.Bold = true;
                    headerTextBox.Style.Font.Size = Telerik.Reporting.Drawing.Unit.Point(8D);
                    headerTextBox.Style.TextAlign = Telerik.Reporting.Drawing.HorizontalAlign.Center;
                    headerTextBox.Style.VerticalAlign = Telerik.Reporting.Drawing.VerticalAlign.Middle;
                    headerTextBox.Style.BorderStyle.Default = Telerik.Reporting.Drawing.BorderType.Solid;
                    //  headerTextBox.Style.BorderWidth.Default = Telerik.Reporting.Drawing.Unit.Pixel(1);
                    columnGroup.ReportItem = headerTextBox;

                    //field that will be displayed
                    Telerik.Reporting.TextBox detailRowTextBox = new Telerik.Reporting.TextBox();
                    detailRowTextBox.Name = "detailRowTextBox" + i.ToString();
                    detailRowTextBox.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(0.572D), Telerik.Reporting.Drawing.Unit.Inch(0.3D));
                    detailRowTextBox.Style.BorderStyle.Default = Telerik.Reporting.Drawing.BorderType.Solid;
                    detailRowTextBox.Style.TextAlign = Telerik.Reporting.Drawing.HorizontalAlign.Center;
                    detailRowTextBox.Style.VerticalAlign = Telerik.Reporting.Drawing.VerticalAlign.Middle;
                    detailRowTextBox.Value = "= Fields.[" + data.Columns[i].ColumnName + "]";
                    table1.Body.SetCellContent(0, i, detailRowTextBox);

                    //add the nested items in the Table.Items collection
                    table1.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { headerTextBox, detailRowTextBox });


                this.DetailSection.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { table1});






    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using Telerik.Reporting;
    using MYScanLibrary;
    using Telerik.Reporting.Drawing;
    using Telerik.Reporting.Charting;

    namespace MYScanDesktop

        public partial class ucReporting : UserControl
            jkdmReport1 myReport = new jkdmReport1();
            Telerik.Reporting.TypeReportSource typeReportSource = new Telerik.Reporting.TypeReportSource();
            public ucReporting()
                typeReportSource.TypeName = typeof(jkdmReport1).AssemblyQualifiedName;

            private void LoadReport()
                //add parameter
                typeReportSource.Parameters.Add(new Telerik.Reporting.Parameter("Location", "efd"));
                String textStartDate = String.Format("{0}", this.datetimePickerStart.Value.ToString("dd/MM/yyyy hh:mm:ss"));
                String textEndDate = String.Format("{0}", this.datetimePickerEnd.Value.ToString("dd/MM/yyyy hh:mm:ss"));
                typeReportSource.Parameters.Add(new Telerik.Reporting.Parameter("StartDate", textStartDate));
                typeReportSource.Parameters.Add(new Telerik.Reporting.Parameter("EndDate", textEndDate));
                typeReportSource.Parameters.AddRange(new ParameterCollection());

                reportviewerMain.ReportSource = typeReportSource;


            private void buttonProceed_Click(object sender, EventArgs e)
                String whereFilter = String.Format(" WHERE et_datetime >= '{0}' AND  et_datetime <= '{1}'",
                        this.datetimePickerStart.Value.ToString("yyyy-MM-dd HH:mm:ss"),
                        this.datetimePickerEnd.Value.ToString("yyyy-MM-dd HH:mm:ss"));



  2. Todor
    Todor avatar
    451 posts

    Posted 31 Jan Link to this post

    Hello fazera,

    Our strong recommendation is to use a Report Parameter for filtering the data. You may use an ObjectDataSource component, in which DataMember receives this parameter as an argument and filters the data as required.

    Concerning your current approach, I think you need to change two things to get the filtering applied successfully.

    First, you need to use InstanceReportSource as you create an instance of the report definition and modify this instance run-time. To take effect, the changes should be passed with the modified instance of the report definition. The TypeReportSource uses System.Reflection to create an instance of the report definition and passes this exact (e.g. original) report instance. Thus, the 'testfilter' value will be always the default, i.e. an empty string.

    Then you need to add the data to the table outside the constructor of the report, for example in an event handler or a method that gets called after modifying the report definition in the code. Currently, the data is assigned in the GenerateReport method that is called only in the constructor, hence even when you change the 'testfilter' value there is no call to the GetData method to get the new data and no modification of the table DataSource to set it to the new data. For example, you may move the GenerateReport method to be called in the setFilter method.

    Progress Telerik

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top