How to find whether field exists in ResultFields collection
Finally...
Assume that we have fieldString already, and reportClientDocument object:
string fieldString;
ReportClientDocument _reportClientDocument;
// fieldString value will look like 'tablename.fieldname',
// so we should split it if we want just field name
char period = '.';
int periodIndex = fieldString.IndexOf(period);
string tableName = fieldString.Substring(1, periodIndex-1);
string fieldName = fieldString.Substring(periodIndex+1, fieldString.Length-(periodIndex+2));
int fldIndex = _reportClientDocument.DataDefinition.ResultFields.Find(fieldName, CrystalDecisions.ReportAppServer.DataDefModel.CrFieldDisplayNameTypeEnum.crFieldDisplayNameName, CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleUserDefault);
if (fldIndex == -1)
{
// do something if not found
}
else
{
// do something if found... or do nothing...
}
If you want full qualified name, use crFieldDisplayNameLong instead of crFieldDisplayNameName, and full fieldString ...
Assume that we have fieldString already, and reportClientDocument object:
string fieldString;
ReportClientDocument _reportClientDocument;
// fieldString value will look like 'tablename.fieldname',
// so we should split it if we want just field name
char period = '.';
int periodIndex = fieldString.IndexOf(period);
string tableName = fieldString.Substring(1, periodIndex-1);
string fieldName = fieldString.Substring(periodIndex+1, fieldString.Length-(periodIndex+2));
int fldIndex = _reportClientDocument.DataDefinition.ResultFields.Find(fieldName, CrystalDecisions.ReportAppServer.DataDefModel.CrFieldDisplayNameTypeEnum.crFieldDisplayNameName, CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleUserDefault);
if (fldIndex == -1)
{
// do something if not found
}
else
{
// do something if found... or do nothing...
}
If you want full qualified name, use crFieldDisplayNameLong instead of crFieldDisplayNameName, and full fieldString ...
0 Comments:
Post a Comment
<< Home