Let's imagine that grid already bound to a data rows and has multiple columns.
I found that I can retrieve a given column position index by:
var fieldsLayout = grid.FieldLayouts[0];
var columnField = fieldsLayout.Fields.Single(f => f.Name == "Column Name");
int columnIndex = ... see below
columnField.Index
- If user does not changed an initial columns ordercolumnField.ActualPosition.Column
- If user has changed an initial columns order
The question is how to know whether an user has changed initial columns order?
Whilst investigating I've found that at the initial stage, when columns order has not been changed yet,
field.ActivePosition.Column
for each columns is0
or== field.Index
, so by introducing following flag:I can get right column position order in following way: