Page 1 of 1
StiFilterEventHandler
Posted: Sat Apr 07, 2007 1:59 pm
by Sandy Pham
I have a report with a filter that is failing due to null data. I think I need to add a StiFilterEventHandler. I tried adding one to my databand, but the method is never called. Can you help me?
Here's what I did:
dataBand.FilterMethodHandler = new Stimulsoft.Report.Events.StiFilterEventHandler(FilterDataHandler);
private void FilterDataHandler(object sender, Stimulsoft.Report.Events.StiFilterEventArgs e)
{
//never gets called
}
Thanks!
Sandy
StiFilterEventHandler
Posted: Sun Apr 08, 2007 3:46 am
by Vital
You need add this event handler after report compilation.
Thank you.
StiFilterEventHandler
Posted: Mon Apr 23, 2007 12:45 pm
by Sandy Pham
How can I retrieve the DataBand from the compiled report so I can set dataBand.FilterMethodHandler?
Thank you.
StiFilterEventHandler
Posted: Mon Apr 23, 2007 2:31 pm
by Vital
For example:
Code: Select all
StiDataBand dataBand = report.CompiledReport.GetComponents()["DataBand1"] as StiDataBand;
Thank you.
StiFilterEventHandler
Posted: Mon Apr 23, 2007 9:07 pm
by Sandy Pham
Thank you, I have the FilterDataHandler working now.
Is this the only event I need to override in order to handle System.DbNull values? My goal is to make sure that I handle any System.DBNull value so that the report does not fail with an object reference exception. I'm thinking I probably need to override a method for Charts as well (StiGetValueEventHandler???).
Or, maybe there is one event that is called by all parts of the report where I could handle System.DBNull values.
Thanks,
Sandy
StiFilterEventHandler
Posted: Tue Apr 24, 2007 4:43 am
by Edward
StiFilterEventHandler
Posted: Tue May 01, 2007 6:53 pm
by Sandy Pham
I've just realized that my FilterMethodHandler isn't working the way I expected. When I provide a FilterMethodHandler, it causes all the rows to be printed in the report. In other words, my report filter is ignored. What I want to do is prevent null values in my dataset from causing object reference exceptions. I still want my report filter to be applied. What should I be doing? Here is my code:
StiComponentsCollection colComp = report.CompiledReport.GetComponents();
foreach (object o in colComp)
{
if (o is StiDataBand)
{
StiDataBand dataBand = o as StiDataBand;
if (dataBand != null)
{
dataBand.FilterMethodHandler = new Stimulsoft.Report.Events.StiFilterEventHandler(FilterDataHandler);
}
}
}
private void FilterDataHandler(object sender, Stimulsoft.Report.Events.StiFilterEventArgs e)
{
object oValue = null;
if (sender is StiDataTableSource)
{
StiDataTableSource sourceTable = (StiDataTableSource)sender;
foreach (StiDataColumn col in sourceTable.Columns)
{
try
{
oValue = sourceTable[col.Name];
if ((oValue == null) || (oValue is System.DBNull))//we need to handle null data because Stimulsoft throws an object ref exception when it hits it
{
if (col.Type == typeof(string))
oValue = "";
else if (col.Type == typeof(DateTime))
oValue = DateValue.CreateEmptyDate(); //minimum date SQL Server can handle
else if (col.Type == typeof(Boolean))
oValue = false;
else //number
oValue = 0;
}
}
catch (Exception ex)
{
//This could happen if a field that was originally put in a report was deleted
Debug.Assert(false, ex.Message);
}
}
}
e.Value = true; //tell row to print in data band
}
StiFilterEventHandler
Posted: Mon May 07, 2007 2:34 am
by Edward
Please modify your code in the following way:
Code: Select all
private void FilterDataHandler(object sender, Stimulsoft.Report.Events.StiFilterEventArgs e)
{
object oValue = null;
if (sender is StiDataTableSource)
{
StiDataTableSource sourceTable = (StiDataTableSource)sender;
foreach (StiDataColumn col in sourceTable.Columns)
{
try
{
oValue = sourceTable[col.Name];
if ((oValue == null) || (oValue is System.DBNull))//we need to handle null data because Stimulsoft throws an object ref exception when it hits it
{
if (col.Type == typeof(string))
{
oValue = "";
}
else if (col.Type == typeof(DateTime))
oValue = DateTime.MinValue;
else if (col.Type == typeof(Boolean))
oValue = false;
else //number
oValue = 0;
e.Value = false; // disable printing of the row in the case of the Null values
return;
}
}
catch (Exception ex)
{
//This could happen if a field that was originally put in a report was deleted
Debug.Assert(false, ex.Message);
}
}
}
e.Value = true; //tell row to print in data band
}
In that case all rows with Null values will not be printed.
Thank you.