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.
Has anybody found a solution to this?
Hello,
Thank you for your post. I can say that the Fields collection order is not taken in to account for the fields order, that’s why you see this approach is not working. So you have to use ActualPosition property of the FieldClass more information you can find here:
http://help.infragistics.com/NetAdvantage/WPF/2011.2/CLR4.0/?page=InfragisticsWPF4.DataPresenter.v11.2~Infragistics.Windows.DataPresenter.Field~ActualPosition.html
and after calling it you should call EnsureUniqueFieldPositions in order to reposition the fields with the new position:
http://help.infragistics.com/NetAdvantage/WPF/2011.2/CLR4.0/?page=InfragisticsWPF4.DataPresenter.v11.2~Infragistics.Windows.DataPresenter.FieldLayout~EnsureUniqueFieldPositions.html
What you need to do is for example :
this.dataGrid.FieldLayouts[0].Fields[0].ActualPosition = new FieldPosition(1, 0, 0, 1);
this.dataGrid.FieldLayouts[0].EnsureUniqueFieldPositions();
Hope this helps you.
Hello Ankit,
I can say that the firing of the events is normal, because our controls doesn’t fire them if the action is done by code. If so, you can execute the desired code after the action you perform. This is like a pattern for custom controls, which is used to have better performance.
Stefan,
For throwing more light on the requirement, this will explain what I really want:
-The "FieldPositionChanged/Changing" event is fired only when user drag/drop columns in the grid.(As far as the documention in your website is concerned).
-I am hoping that is correct, in that case, I want to achieve all the column's position information even after I have changed the columns by some other means.
For Eg, I changed the collection and bind it accordingly to the grid. In this case, even if the ActualPosition would have changed for each column, but the FieldPositionChanged event would not fire, and thereby I would not get the details to save the layout, in which case, while loading the same layout, the column order would be intermittent.
-Can you suggest me some solution for the above wired scenario. I would be very grateful to you.
Thanks,
Ankit Srivastava
Now, All I want is a property which is fired whenever any fields in the dataGrid changes its position, so that I can fire the FieldPositionChangedEvent and get the XML file with field's position information.
This works fine in the scenario where I an dragging and dropping the columns and then calling SaveCustomization().
But in between the two steps, I am adding one more step which is:
-Managing columns which shows the columns you want to add or remove, after doing that when I am hitting OK, in the back-ground I am clearing the customization with FieldPosition to accomodate the changes.
-And then I hit to SaveCustomization. I guess this is the reason why the XML doesn't gets the attribute's value for ActualPosition(ColSpan,RowSpan,Row,Column)
Is there a way in which we can save the customizations.
Thank you for your post. I have been looking into it and I and I created a sample project for you following your scenario and everything seems to work ok on my side. If the sample doesn’t satisfies all your needs feel free to modify it, so it reproduces your behavior and send it back to me for further investigation. I tested the project both with the RTM and latest Service Release of version 11.1.
Looking forward for your reply.