Anonymous Type property ordering in VB

Anonymous Type property ordering in VB

Many people have noticed when binding an anonymous type to a grid in VB that the order of the properties does not reflect the order that they were specified in the projection (Select) clause. Instead, they appear alphabetized. Consider the following query:

Dim query = From c In Customers _
                    Select c.LastName, c.FirstName, c.BirthDate

If you bind this query to a DataGrid or DataGridView and allow the columns to be generated automatically, the results will be displayed with the following column ordering: BirthDate, FirstName, LastName. Notice that the columns are ordered alphabetically based on the property name.

I just received word that this behavior is changing in the next update to VB. After this release, the property order should be retained from the projection clause, just as it is in C#.

Posted on 5/16/2008 10:19:00 AM - Comments(3)
Categories: VB Dev Center LINQ VB VS 2008
Comments:
  • Gravatar You said it is changing in the next update. are you referring to SP1 beta, or SP1, or SP2.
    Ralph Esslinger (Posted on 5/20/2008 7:50:00 AM)
  • Gravatar Ralph, It isn't in the SP beta, but should be in SP1 according to my source.
    Jim Wooley (Posted on 5/20/2008 3:34:00 PM)
  • Gravatar This is a surprisingly annoying quirk.



    Is there a workaround? Is it possible to programmatically rearrange the columns in a Datagridview?


    Kelvin Jeffs (Posted on 7/3/2008 7:28:00 PM)