Olá,
Deveria funcionar. Estou usando isso para obter a coleção, então a adição está comentada, mas deve funcionar para você:
{
btnReportObjects.Text = "";
flcnt = 0;
foreach (CrystalDecisions.ReportAppServer.ReportDefModel.ReportObject reportObject in rptClientDoc.ReportDefController.ReportObjectController.GetAllReportObjects())
{
var reportSection = rptClientDoc.ReportDefController.ReportDefinition.FindSectionByName(reportObject.SectionName);
for (int index = 0;
index < reportSection.Format.ConditionFormulas.Count;
++index)
{
var formula = reportSection.Format.ConditionFormulas[(CrystalDecisions.ReportAppServer.ReportDefModel.CrSectionAreaFormatConditionFormulaTypeEnum)index];
var NewFormula = reportSection.Format.ConditionFormulas[(CrystalDecisions.ReportAppServer.ReportDefModel.CrSectionAreaFormatConditionFormulaTypeEnum)index];
try
{
if (formula.Text != null)
{
textBox1 = "Fórmula de condição: " + formula.Text.ToString() + "\n";
textBox1 += "Seção " + reportSection.Name + "\n";
}
}
catch (Exception ex)
{
btnReportObjects.Text += "\nExceção: " + ex.ToString();
}
btnReportObjects.Text += textBox1;
btnReportObjects.AppendText("\n");
++flcnt;
btnCount.Text = flcnt.ToString();
//// Verifica a fórmula adicionando-a ao relatório para verificar a sintaxe
//CrystalDecisions.ReportAppServer.ObjectFactory.ObjectFactory objFactory = new CrystalDecisions.ReportAppServer.ObjectFactory.ObjectFactory();
//CrystalDecisions.ReportAppServer.DataDefModel.FormulaField Formula = (CrystalDecisions.ReportAppServer.DataDefModel.FormulaField)objFactory.CreateObject("CrystalReports.FormulaField");
//Formula.Type = CrystalDecisions.ReportAppServer.DataDefModel.CrFieldValueTypeEnum.crFieldValueTypeStringField;
//Formula.Syntax = CrystalDecisions.ReportAppServer.DataDefModel.CrFormulaSyntaxEnum.crFormulaSyntaxCrystal;
//Formula.Text = @"whilereadingrecords; ""A"""; // "hello Ludek = 1"; // resultField.Text; // "n=3"; {Customer.Customer Credit ID} + 1 @"whilereadingrecords; ""A"""
//Formula.Name = "TestDon"; // "TestDon"; //† resultField.Name; //"testformula";
//String FormulaMessage = rptClientDoc.DataDefController.FormulaFieldController.Check(Formula);
//if (FormulaMessage == null)
//{
//††† // então adiciona a fórmula condicional se estiver correta
//††† string newFormulaText = "'Funcionar' = 'Funcionar'";
//††† // Clona um formato de seção e usa ReportSectionController.SetPropety para modificar as ConditionFormulas
//††† CrystalDecisions.ReportAppServer.ReportDefModel.SectionFormat newFormat = reportSection.Format.Clone(true);
//††† newFormat.ConditionFormulas[(CrystalDecisions.ReportAppServer.ReportDefModel.CrSectionAreaFormatConditionFormulaTypeEnum)index].Text = newFormulaText;
//††† rptClientDoc.ReportDefController.ReportSectionController.SetProperty(reportSection, CrReportSectionPropertyEnum.crReportSectionPropertyFormat, newFormat);
//}
//else
//††† btnReportObjects.Text += "Há erros na fórmula: " + FormulaMessage.ToString() + "\n";
}
}
}
Don