Reputation: 4057
I have a WPF datagrid with autogeneratecolumns = true. It is bound to a list of POCO Is there anyway I can set the column order by maybe setting some XML documentation on the properties in the class?
Obviously I can set autogenerate to false, and hard code the columns, but I'm wondering is there some other way of decorating my class/properties to take care of this.
Upvotes: 4
Views: 2050
Reputation: 81
Not the nicest method, but works for me:
In the "AutoGeneratedColumns" event, you can set your columns DisplayIndex for each column by its header.
private void datagrid1_AutoGeneratedColumns(object sender, EventArgs e)
{
datagrid1_.Columns.FirstOrDefault(x => x.Header.ToString() == "header").DisplayIndex = 0;
}
Take care of exceptions, etc...
Or I think the order of properties in the declaration of the class forecasts the autogenerated column order.
Upvotes: 3