Hossein Kurd
Hossein Kurd

Reputation: 4585

How to show Filtered Data from DataGridView into StimulReport?

How can I show Filtered Data from DataGridView into StimulReport?

There are codes I tested:

public void CreateStimulSoftReport()
{
    System.Diagnostics.Debug.WriteLine("CreateStimulSoftReport ...");
    StiReport stReport = new StiReport();

    //If Template has already been created then load that template
    stReport.Load(@"C:\Tools\Test\ReportExcel.mrt");
    stReport.Compile();

    #region Report Data Creation Section

    DataSet dataSet = new DataSet("DS1");

    System.Data.DataTable table = new System.Data.DataTable("Demo");
    table.TableName = "DataBand1";
    table.Columns.Add(new DataColumn("id", typeof(int)));
    table.Columns.Add(new DataColumn("tel_usage_new", typeof(string)));
    table.Columns.Add(new DataColumn("tel_usage_former", typeof(string)));
    table.Columns.Add(new DataColumn("terminal_cable30", typeof(string)));
    table.Columns.Add(new DataColumn("terminal_cable40", typeof(string)));
    table.Columns.Add(new DataColumn("terminal_voip_u6", typeof(string)));
    table.Columns.Add(new DataColumn("terminal_cable40_u47", typeof(string)));
    table.Columns.Add(new DataColumn("description", typeof(string)));

    //Fill Data in Table
    //Here GRID_VIEW_DATA_ITEMS is your ObservableCollection or any collection that is bound to your DataGrid
    foreach (DataGridViewRow row in dataGridView1.Rows)
    {
        System.Diagnostics.Debug.WriteLine("CreateStimulSoftReport ID : " + row.Cells[0].Value.ToString());
        DataRow dr = table.NewRow();
        dr["id"] = row.Cells[0].Value.ToString();
        dr["tel_usage_new" ] = row.Cells[1].Value.ToString();
        dr["tel_usage_former"] = row.Cells[2].Value.ToString();
        dr["terminal_cable30"] = row.Cells[3].Value.ToString();
        dr["terminal_cable40"] = row.Cells[4].Value.ToString();
        dr["terminal_voip_u6"] = row.Cells[5].Value.ToString();
        dr["terminal_cable40_u47"] = row.Cells[6].Value.ToString();
        dr["description"] = row.Cells[7].Value.ToString();
        System.Diagnostics.Debug.WriteLine("CreateStimulSoftReport tel_usage_new : " + dr["tel_usage_new"]);
        table.Rows.Add(dr);
    }
    System.Diagnostics.Debug.WriteLine("Create StimulSoftReport table Rows : " + table.Rows.Count);

    dataSet.Tables.Add(table.Copy());
    System.Diagnostics.Debug.WriteLine("CreateStimulSoftReport dataSet tables : " + dataSet.Tables.Count);

    #endregion

    //Register Report Dataset with Stimulsoft Report
    stReport.RegData("DS1", "DS1", dataSet);
    stReport["date_time"] = DateTime.Now.ToString("yyyy-MM-dd hh-mm-ss dddd");
    stReport.Dictionary.Synchronize();
    stReport.Render();
    stReport.Show();

}

But It shows a blank report Page.

Upvotes: 0

Views: 112

Answers (1)

Vahid Iranshad
Vahid Iranshad

Reputation: 41

1- you must use DataBand In Report
2- DataBand must assigned with DS1
3- write this before RegData:

stReport.Tables[0].TableName = "DS1";
stReport.Namespace = "DS1";
stReport.DataSources.Clear();
stReport.Dictionary.DataSources.Clear();

4- if you need variable "date_time" create variable in report and set value with

stReport.Dictionary.Variables["date_time"].Value = DateTime.Now.ToString("yyyy-MM-dd hh-mm-ss dddd");

Upvotes: 1

Related Questions