XamDataGrid Column position index: Field.Index or Field.ActualPosition.Column

Imagine that the grid is already bound to data rows and has several columns.

I found that I can get the given column position index:

var fieldsLayout = grid.FieldLayouts[0];
var columnField = fieldsLayout.Fields.Single(f => f.Name == "Column Name");
int columnIndex = ... see below
  • columnField.Index - If the user has not reordered the starting columns
  • columnField.ActualPosition.Column - If the user has reordered the starting columns

The question is, how do you know if the user has changed the original column order?

+5
source share
2 answers

During the study, I found that at the initial stage, when the order of the columns has not yet been changed, field.ActivePosition.Columnfor each column 0or == field.Index, therefore, by entering the following flag:

bool initialOrderChanged = fieldsLayout.Fields.Any(f => 
                                       f.ActualPosition.Column != 0 
                                       && 
                                       f.ActualPosition.Column != f.Index);

:

 int position = initialOrderChanged
                      ? field.ActualPosition.Column
                      : field.Index,
+4

. - , .

+1

All Articles