Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 order
  • columnField.ActualPosition.Column - If user has changed an initial columns order

The question is how to know whether an user has changed initial columns order?

like image 496
sll Avatar asked Oct 20 '11 11:10

sll


2 Answers

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,
like image 180
sll Avatar answered Oct 12 '22 09:10

sll


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.

like image 30
Lajos Arpad Avatar answered Oct 12 '22 07:10

Lajos Arpad