DataGridView column order?



I am playing around with the DataGridView control, and am curious if anyone knows how the default order for columns is chosen when the DataSource is a simple IList containing objects with public properties?

I assume that when you bind to an actual database data source, the order of the columns matches the order of fields in the records in the database. That is, the order of the columns in the table you're binding to. But a class has no similar natural ordering per se.

I made up a test class with the public properties Name, Time, and Northbound. They are declared in the class in that order. I would have guessed that the DataGridView would use those properties either in alphabetical order, or in the order that they are declared in the class (on the assumption, possibly wrong, that the order I declare them in the class affects how they are managed internally by the run-time). However, the DataGridView uses neither of these. Instead, it orders them Time, Name, and Northbound.

Using reflection, I can see that the properties are in fact at least listed in the members of the class in the order in which they were declared in the class. So, whatever DataGridView is doing, it's not just pulling them out of the list in order as they appear in the collection of members that reflection provides.

What criteria is DataGridView applying when deciding which order to display the columns?

Pete

p.s. This is partially just an academic question, as I can of course reorder the columns to suit my intent. I just figured if I knew how DataGridView was deciding to order the columns, I could avoid having to reorder them after the DataSource has been bound. And of course, I'm curious.
.



Relevant Pages

  • Re: DataGridView column order?
    ... GetItemProperties on the BindingManagerBase to get the property information ... (on the assumption, possibly wrong, that the order I declare them in the ... the DataGridView uses neither of these. ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Global DataSet
    ... presentation project with a DataGridView I choose "Add New Data Source..." ... now select the following in the DataGridView Tasks window... ... Project Data Sources ... Then specify the datasource in the datagridview ...
    (microsoft.public.vsnet.ide)
  • Re: Gebundene DataGridView auf TabPage - ausgeblendete Spalte erscheint
    ... Ich ändere zur Laufzeit die DataSource der BindingSource-Komponente ... wiederrum an das DataGridView gebunden ist. ... Nun ist die Spalte ID nicht mehr sichtbar ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: Setting DatagridView column type as Combo after databind
    ... Create your DataGridView and add 10 columns to it with 3 being ... bound to when you eventually databind the grid. ... DataSource or DataMember properties) set the AutoGenerateColumns ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: Gebundene DataGridView auf TabPage - ausgeblendete Spalte erscheint
    ... Nach dem Starten der Anwendung ist das DataGridView ... Bei DataGridView.AutoGenerateColumns = True ... werden nun wieder alle Spalten der neuen DataSource im ... Grid änderst und wann und wo Du jeweils die Spalte ID ...
    (microsoft.public.de.german.entwickler.dotnet.vb)

Loading