Reorder datagrid columns or index

This is something that I can’t believe that I couldn’t find out, please tell me that I am missing something simple ...

I have a datagrid, I populate it with LINQ, as well as a custom class to add data to it.

Subsequently, I need data in a certain order - it seems that they ignore me.

How to change column properties like index etc.

here is the LINQ code I'm 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} 
+4
source share
3 answers

solvable

I can’t believe how many things I had to make my way to find this!

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

Datagrid.Columns("Zone").DisplayIndex = 0

or

Datagrid.columns(1).DisplayIndex=0

+7
source

What you see is a consequence of how VB generates anonymous types in RTM Visual Studio 2008. The compiler sorts the properties alphabetically. Therefore, no matter what order you specify, if the data links the query, the columns will be displayed in alphabetical order.

In Visual Studio 2008 Service Pack 1 (SP1), the VB compiler made changes to solve this problem. Anonymous types now generate anonymous type members just as you specify them in the code. If you upgrade to VS2008 SP1, you will see a change in this behavior.

Detailed article on the topic

+2
source

I'm not sure exactly what is going on, but something to consider ...

At what point do you change the columns? If it's too late, you may need a rebound into the grid, as a result of which it will be redrawn. Usually, when I change something, and I do not see its effect on the screen, this is due to the mandatory order.

+1
source

All Articles