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 orderThe 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 is 0
or == field.Index
,
so by introducing following flag:
bool initialOrderChanged = fieldsLayout.Fields.Any(f =>
f.ActualPosition.Column != 0
&&
f.ActualPosition.Column != f.Index);
I can get right column position order in following way:
int position = initialOrderChanged
? field.ActualPosition.Column
: field.Index,
Store the initial column list and compare the initial column list with the actual list. If there is any difference, in the order, the column order was changed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With