ReportViewer RDLC – How to show an enum’s string representation


I’m building a report using ReportViewer. I’m setting the Data Source to a collection of model objects. One of the fields on the model is an enum. When the report renders, it is showing the enum’s numeric value. I want it to show the string representation of the enum instead.


In the field I put the following expression:

=System.Enum.GetName(First(Fields!MPAARating.Value).GetType(), Fields!MPAARating.Value)
Code language: plaintext (plaintext)

Here’s what it looks like in the report design:

And this is what the report looks like now:



using System; using System.Windows.Forms; namespace ReportViewerRDLC { public partial class frmReportViewer : Form { public frmReportViewer() { InitializeComponent(); } private void frmReportViewer_Load(object sender, EventArgs e) { var movies = new MovieCollection() { new Movie() { Name = "Pulp Fiction", MPAARating = MPAARating.R }, new Movie() { Name = "The Dark Knight", MPAARating = MPAARating.PG13 } }; this.MovieCollectionBindingSource.DataSource = movies; this.rvMovies.RefreshReport(); } } }
Code language: C# (cs)

Movie.cs – the model

namespace ReportViewerRDLC { public class Movie { public string Name { get; set; } public MPAARating MPAARating { get; set; } } }
Code language: C# (cs)

MovieCollection.cs – the model binding list

using System.ComponentModel; namespace ReportViewerRDLC { public class MovieCollection : BindingList<Movie> { } }
Code language: C# (cs)

MPAARatingEnum.cs – the enum

namespace ReportViewerRDLC { public enum MPAARating { G, PG, PG13, R } }
Code language: C# (cs)

Leave a Comment