Hi,
Can you please help me with below requirement?
I have grid with 3 fixed columns and 24 other (non fixed) columns. When user changes width of any non-fixed column by dragging with mouse, I want to all remaining non-fixed columns to expand or shrink automatically to that size.
Hello Harinatha,
This is actually expected. The XamDataGrid SaveCustomizations method only saves end-user modifications to the grid. Certain properties are not taken into account if they are programmatically applied or not controlled by the user. That said, many of the properties that are saved are based on internal properties to the fields that are modified as the user makes these changes. The Width property of the Field is not one of these properties, as the user-interactions have no effect on the actual Width property. When a user resizes a field, the internal LabelWidth and CellWidth properties are what get serialized.
With the PropertyChanged logic in place here, though, nothing should really change when you are trying to load your Field widths. When you load your customizations, the PropertyChanged event should fire for these LabelWidthResolved and CellWidthResolved properties as long as one of your Fields has that property serialized. That is, as long as a single field has had its width modified by the user, and not by clicking the button in the case of the sample I sent you, all of the Fields should have their customizations loaded normally due to the PropertyChanged logic.
If you are looking to actually be able to save all of the properties on the Fields, whether or not they are programmatically modified, I would recommend utilization of the Infragistics Persistence Framework, which you can read about here: http://ko.infragistics.com/help/wpf/control-persistence-framework. This framework takes all things into account, rather than just the user interactions.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
I have done these changes. The problem is when I try to save customizations by using _dataGrid.SaveCustomizations(), the result string has only the column that was changed, other columns does not have labelwidth property serialized.
Can you help me?
I apologize for that, I must have misread your requirement as resizing the fixed fields rather than the non-fixed fields. In this case, you would check for IsFixed = false when applying the new size.
Regarding the above line being fired again, this is expected as the PropertyChanged events are hooked for every field into the same event handler in the case of the sample project. To prevent this firing from happening multiple times, you can unhook the Field from that PropertyChanged event handler prior to setting the new Width and then re-hook the event after changing the Width property.
Regarding identifying whether the resize was caused in code or by the user, I would recommend using a flag for the programmatic resize. If the resize comes from your code, I would imagine that somewhere in your application you would know about it. If you kept a bool "flag" property for this action and set it just before when the programmatic resize happens, you could check this in the PropertyChanged event and know that it happened programmatically if the flag is set to a certain value. You can then act accordingly and set the flag back to its default value. Any other times that the PropertyChanged event fires for your Width property, you can assume it was done by the user, as the setting of the flag would have happened were it done programmatically.
I have attached a modified version of the sample project I had sent you to demonstrate the above.
Thank Andrew. I want to change the width of non-fixed fields.
foreach (Field f in owner.Fields){f.Width = new FieldLength(size);}
Above line causes the same event(s) to be fired for each field again. I want to somehow either stop firing these events or identify whether the resize caused by user or code...
Any idea to solve this ?
The XamDataGrid doesn't really expose any sort of FieldResizing event that you could use for this requirement, but each of the Fields in the XamDataGrid do expose a PropertyChanged event that you can use instead, and so I would recommend handling that event to implement this functionality.
Depending on whether or not you resize the Fields in your grid by resizing the data-cell area or by resizing the actual header itself, this PropertyChanged event may fire for two separate properties, CellWidthResolved and LabelWidthResolved, respectively. So, if you check e.PropertyName (where is the event arguments) for either of those properties, you can loop through your XamDataGrid fields, checking the IsFixed property of each, and if it is fixed, you can set the Width of those fixed fields to the value returned by the property that changed for the Field sender of the PropertyChanged event.
I have attached a sample project to demonstrate the above. I hope this helps you.