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.
Hello sebl,
The FieldCollection object inherits an ObservableCollection<Field>. You can utilize the ObservableCollection's Move() method to accomplish what you are looking for. For example:
grid.FieldLayouts[0].Fields.Move(1, 0);
The two integer parameters are the oldIndex and newIndex, respectively.
For more information, you can see the documentation here.
OK,
This does allow me to change the index of the field, but the property ActualPosition is still the one that seems to be used when displaying the fields.
In the end, all fields remain at their current position.
OK, Thanks. I hope there is some kind of workaround.
What I was saying is that you can reproduce the problem by either changing a column's position by Drag&Drop OR calling LoadCustomizations.
I will create a support case on your behalf and link it to this issue. There is a way around this. The Column, Row properties are not take into consideration if the user has moved,fixed, loaded customizations. That is why you have to call the ClearCustomizations() method. Here is one option that you have:
xamDataGrid1.ClearCustomizations(
CustomizationType.FieldPosition);
FieldCollection fields = xamDataGrid1.FieldLayouts[0].Fields;
fields.Move(0, 3);
Regards,Alex.
Guys,
I am experiencing this issue now.
Here is my scenario:
Launch UI
-Load Default Fields
-Allow user to customize visibility and position of the field via a field selector control
-Call SaveCustomizations and persist this info into data store.
Next time launching UI,
-call LoadCustomizations to apply user settings
-And allow user to reconfigure the view (columns/positions)
With combination of this field selector GUI and user performing drag and drop action on the grid, I am experiencing different behavior when programatically move the columns around.
For me to understand this better,
A.
What is the value of ActualPosition.Column before user perform drag and drop?
Does the actual position gets changed after doing drag and drop?
Does the position of the dragged field get reset to original value when ClearCustomizations(CustomizationType.FieldPosition) gets called? If so it get reset to the position before calling LoadCustomization or position after calling LoadCustomizations?
B.
What is the expected value for Fields.Move oldIndex? Is that the current field index in Fields collection OR it is the Field.ActualPosition.Column OR it is Field.Column
C. What should I do if I want user to do drag and drop to move the columns around and/or use my field selector UI to perform the same.
I guess I need a solution that would work in both the cases where by I can move the columns programmatically irrespective of user performed drag and drop or not.
I would have to debug on this to understand it better, it would save my cycles if anyone had researched on this already.
Thanks for helping out.
Any update on nmuthu's questions? I do not use customization but I have the similar problems with Field.ActualPosition.Column values. It has the value that does not correspond to real UI visible position after moving columns via drag&dropping.
Thanks, Alex.
I am now using 2010.03 for a different project and just wondering is this fix is already in this version?
Thanks,
Muthu
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
Hi, any update on this, is the index is zero based or one based?