StiFilterEventHandler
-
- Posts: 62
- Joined: Mon Dec 11, 2006 1:43 pm
- Location: U.S.A.
StiFilterEventHandler
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
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
You need add this event handler after report compilation.
Thank you.
Thank you.
-
- Posts: 62
- Joined: Mon Dec 11, 2006 1:43 pm
- Location: U.S.A.
StiFilterEventHandler
How can I retrieve the DataBand from the compiled report so I can set dataBand.FilterMethodHandler?
Thank you.
Thank you.
StiFilterEventHandler
For example:
Thank you.
Code: Select all
StiDataBand dataBand = report.CompiledReport.GetComponents()["DataBand1"] as StiDataBand;
-
- Posts: 62
- Joined: Mon Dec 11, 2006 1:43 pm
- Location: U.S.A.
StiFilterEventHandler
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
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
-
- Posts: 62
- Joined: Mon Dec 11, 2006 1:43 pm
- Location: U.S.A.
StiFilterEventHandler
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
}
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
Please modify your code in the following way:
In that case all rows with Null values will not be printed.
Thank you.
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
}
Thank you.