Column order when binding DataGrid with typed collection

G

Gerardo A Medina

I need help for setting the order of columns in a
DataGrid populated by binding it with a fixed-type
collection of custom objects. Actually I don´t even know
where to start.
The binding was easy and works with a simple

myDataGrid.DataSource = myCollection;

But the order of the columns messes the data; related
columns appear separated each other. How can I specify
column ordering? Should I change the order in the
DataGrid (How?). Or there is a way to make Reflection
work automatically on the type to get the properties and
fields on the right order, so whenever I bind them with a
grid the columns appear in the right place?
 
M

Matt Garven

You can use ITypedList (or is it ICustomTypeDescriptor? or both?) to return
the properties in the order you want them to appear in your DataGrid.

Alternatively, you can define a custom GridColumnStyle which contains your
columns in the correct order.

Regards,
Matt

I need help for setting the order of columns in a
DataGrid populated by binding it with a fixed-type
collection of custom objects. Actually I don´t even know
where to start.
The binding was easy and works with a simple

myDataGrid.DataSource = myCollection;

But the order of the columns messes the data; related
columns appear separated each other. How can I specify
column ordering? Should I change the order in the
DataGrid (How?). Or there is a way to make Reflection
work automatically on the type to get the properties and
fields on the right order, so whenever I bind them with a
grid the columns appear in the right place?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top