Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change datagrid columns order or index

This is something that I cannot believe I have not been able to figure out -- please tell me I am missing something 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}
like image 568
Joe Ruder Avatar asked May 09 '09 20:05

Joe Ruder


3 Answers

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

like image 71
Joe Ruder Avatar answered Sep 20 '22 22:09

Joe Ruder


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

  • http://www.thinqlinq.com/default/VB-Ordering-of-Anonymous-Type-Properties-change-with-VS-2008-SP1.aspx
like image 21
JaredPar Avatar answered Sep 19 '22 22:09

JaredPar


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.

like image 42
oglester Avatar answered Sep 19 '22 22:09

oglester