Search code examples
c#visual-studiovisual-studio-2012rdlcmicrosoft-reporting

Why isn't the Visual Studio Report Data screen showing all the available Datasets?


In the below example I have a number of public classes that are defined in a namespace. These are going to be instantiated, bound to ReportDataSets and handed off to my ReportViewer control to generate a report from my report definition files. When I try to access these classes in the Report Data window of the report designer for my .RDLC files, however, it only shows a few of the classes I've defined. What's going on, where are all the rest?

namespace Namespace1
{
    public class Class1
    {
        public string String1 { get; set; }
    }

    public class Class2
    {
        public string String1 { get; set; }
    }
}

Note: If you try to add the Class1 definition to the report page that requires Class2's data and then bind Class2 to the ReportDataSet before the report is generated, an exception will be thrown.


Solution

  • When there are a number of classes with the same schema (all properties and their datatypes are the same), only the one that's first alphabetically will show up. But both will show up in the below example, because they do not have the same name for all properties (in this case, the one string).

    namespace Namespace1
    {
        public class Class1
        {
            public string String1 { get; set; }
        }
    
        public class Class2
        {
            public string String2 { get; set; }
        }
    }