Who can give me a hint on this case?

Let's say I have an object "MyObject" with the following properties (this is a breakdown for easier explination)

public clas MyObject
    public string Column { get; set; }
    public string Value { get; set; }
    public int Row { get; set; }

When this get's populated I then create a List<MyObject> which I need to sort based on different column names.
Ex: this is how the list would look like when populated. The ElementAt(i) is there to signify that there is a MyObject instance in the list.

ElementAt(i) Row Column Value
0 1 FirstName John
0 1 LastName Doe
0 1 BirthDate 01-01-1900
1 2 FirstName Jane
1 2 LastName Doe
1 2 BirthDate 01-01-1901
2 3 FirstName Mary
2 3 LastName Poppins
2 3 BirthDate 01-01-1910
3 4 FirstName Mark
3 4 LastName Whalberg
3 4 BirthDate 01-01-1905

As you can see I can easily pivot it to a table which get displayed into a report afterwards. How would you go about sorting it by "Column" value before sending it to the report. Right now I only found a cumbersome way of translating it to a DataTable and do the sorting there and then recreate the list to pass to the report.


3 Years
Discussion Span
Last Post by pitic

Use Linq:

myList.OrderBy(item => item.Column);

Or am I missing something?

Edited by pritaeas


Yes you are. That would just give me an orderd list like this.

BirthDate    01-01-1900
FirstName    Jane
FirstName    John
LastName     Whalberg

The list example I gave should give you an idea of what the table will look like.

FirstName LastName BirthDate

With their sorted values. The problem is I have to sort the List before I turn it into a table.


Why don't you combine the three rows/objects into a single object, or is that not an option?

Edited by pritaeas: Removed. Wrong.


It's a dynamic table I'm working with and I don't know upfront the number of rows I have. So depends on user selection. He could select 3 columns to display or 300. So the "MyObject" class would store the column name and value, and for the rows I'm using the List<MyObject>.

The problem is I'm using SSRS to build some custom reports (user made) and I have to make everything dynamic. Which pretty much limits the possibilities.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.