views:

828

answers:

3

OK,

This is something that I cannot believe I have not been able to figure out -- please tell me I am missing someting simple...

I have a datagrid, I am filling it with Linq as well as a custom class to add data to it.

Afterwards, I need the data in a specific order - it seems to ignore me.

How do I change a columns properties, like index etc??

here is the linq code I am using:

thanks in advance...

 Dim query = From m In db.details _
                Where m.InboundDate >= CType(MonthCalendar1.SelectionStart, DateTime) _
                And m.InboundDate <= CType(MonthCalendar1.SelectionEnd, DateTime).AddHours(23).AddMinutes(59) _
                And m.ClientNo = 1 _
                  Join md In db.Manifests On md.ManifestID Equals m.MainID _
                Select New GridData With {.manifestID = m.MainID, .InboundDate = m.InboundDate, .Zip = m.Zip, .LadingPkgQty = md.LadingPkgQty, .Weight = m.Weight, .Zone = m.Zone, .Fuel = 23, .LineHaul = Nothing, .Freight = Nothing, .BilledAmount = Nothing, .PackageRate = Nothing, .LTL = Nothing}
+1  A: 

What you're seeing is an effect of how VB generated anonymous types in Visual Studio 2008 RTM. The compiler would sort the properties alphabetically. Hence no matter what order you specified, if you data bind a query, the columns will display alphabetically.

In Visual Studio 2008 SP1, the VB compiler made a change to address this behavior. Anonymous types will now generate anonymous type members in the same way you specify them in code. If you upgrade to VS2008 SP1, you should see a change in this behavior.

Detailed article on the subject

JaredPar
I am running the latest service pack....What about simply changing the column postion after the fact?thanks...
MostlyLucid
OK -- I see what you are saying now...However, surly there is a way to change the order at runtime?Your time is appriciated,Joe
MostlyLucid
A: 

I am not sure the specific of what is going on, but something to consider...

At what point are you modifying the columns? If too late, it may need to be rebound to the grid, causing it to be redrawn. Usually when I change something and I don't see its effect on the screen, it is due to binding order.

Greg Ogle
+1  A: 

Solved

I cannot believe how much stuff I had to wade through just to find this!

It seems Sooooo obvious now (like much of .net after the fact!)

Datagrid.Columns("Zone").DisplayIndex = 0 or Datagrid.columns(1).DisplayIndex=0

MostlyLucid