Hi,
Is there any way to change the field position by code in the field layout?.
The ActualPosition property is read only and changing the Column property has not effect... I guess that the ActualPosition property as priority over the Column property.
Anyone?
Thanks.
From what I can see even using the latest release moving columns programmatically is a disaster. ActualPosition is not reliable at all due to hidden columns and user customizations etc.
Please tell me this is going to be resolved ASAPas without this feature working properly our users are going to be very unhappy. I have submitted another support case CAS-62071-RMZ411 on this issue.
Doug Rees
Polo Ralph Lauren
Hi Charlie, Ok, Thanks for clarifying.
Hello Muthu.
The grid is functioning as designed. To programmatically move a column in the collection and then have the UI reflect that change you need to create a new FieldPosition object and pass in the new positions.
There is an overload on the FieldPosition constructor that takes 4 integers: int column, int row, int columnSpan, int rowSpan. The first parameter (the column) is not zero based. The values that you pass into this constructor are positions in a layout manager; they are not actual positions in an ObservableCollection, which is what the Field.Index is. The FieldsCollection derives from ObservableCollection so Field.Index is the zero based position of the Field object in the collection.
However, positions in a layout manager are different; they are not zero based. If the fields[0] is already at column 0 and then the next 3 fields are at column 1, 2 and 3 respectively, you will have to set the column to 4 to make sure it's after the last one. This is what these lines of code will do for the sample I attached to my last response:
fields[0].ActualPosition = new FieldPosition(4, 0, 1, 1);this.xamDataGrid1.FieldLayouts[0].EnsureUniqueFieldPositions();
That code will move the first field in FieldLayout[0] to the last position. Please let me know if you have any questions.
Sincerely,
CharlieSenior Developer Support Engineer MCTS
Is this function as designed or is a Bug?
But it looks like it is ignoring the first column for some reason, I noticed the same behavior for the Move method as well and reported as a separate issue..
Yes, you are correct. The FieldPosition is not zero based; it starts at 1. Field indexes within the FieldLayoutsCollection are zero based, but the FieldPositions are not.
CharlieSenior Developer Support EngineerMCTS