3

I have converted several reports from the visual studio 2008 report builder format to the visual studio 2010 report builder format. This involved converting the .rdlc files and referencing the new report viewer assembly, version 10.0 (old was 9.0).

I have found that enumeration values are now displayed as numeric values, whereas the older version displayed the string representation of the enumeration value. I can't figure out how to format the value so the string is displayed.

I use IEnumerable of objects as my data sources. I know that I could add properties to the objects to expose the enumeration values as strings - but I would consider this a last resort being that I am talking about hundreds of reports and objects plus adding these properties is more of a hack solution that really add no purpose to the object model.

So I am hoping there is a cleaner way to accomplish formatting enumeration values directly through the report designer.

In the following enumeration, PaymentBucketTyp.PRIN should be displayed on the report as 'PRIN' not '0', PaymentBucketType.AINT should be displayed as 'AINT':

Public Enum PaymentBucketType
    PRIN
    AINT
    CORT
    ATTY
    MISC
End Enum

I have tried the following expressions:

=Fields!Bucket.Value
=Fields!Bucket.Value.ToString()
=CStr(Fields!Bucket.Value)
=Fields!Bucket.Value.ToString("G") 'produces #Error

I have also tried setting format of the textbox to ="G"

UPDATE - 02/28/2012 I have also tried System.ComponentModel.DataAnnotations attributes, still no luck:

[System.ComponentModel.DataAnnotations.Display(Name = "PRIN")]
[System.ComponentModel.DataAnnotations.DisplayFormat(DataFormatString="G")]
J Cooper
  • 4,828
  • 3
  • 36
  • 39
  • I left a solution here: [ReportViewer and Enum](http://social.msdn.microsoft.com/forums/en-US/a45a3786-5bf7-4661-91bc-587e0b43e849/reportviewer-and-enums) –  Nov 08 '13 at 04:56
  • @f01senoj - although it would work, it would be my least favorite option because it is not a very scalable solution when your talking about adding custom code to hundreds of reports – J Cooper Nov 15 '13 at 17:38

2 Answers2

0

After a long digging on the internet, finally I found a solution. In field expression just put this code :

=System.Enum.GetName(First(Fields!YourFieldBasedOnEnumType.Value).GetType(), Fields!YourFieldBasedOnEnumType.Value)

source

That solution is works for me.

Satria Janaka
  • 463
  • 4
  • 15
0

Try this:

=First(Fields!YourFieldBasedOnEnumType.Value, "DatasetsName")
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83