[DevExpress Support Team: CLONED FROM Q514530: How to change a DetailView editor or ListView column caption dynamically]
Hello,
When i implemet https://supportcenter.devexpress.com/ticket/details/t601244/how-to-change-property-caption-at-runtime-based-on-another-property-value solution to my Blazor project always show "Unsaved changes will be lost…" message?
C#void ObjectSpace_ObjectChanged(object sender, ObjectChangedEventArgs e) {
var obj = this.View.CurrentObject as OrderSlip;
if (obj != null) {
if (e.PropertyName == "StoppageRate") {
var _peditor_stoppagerate = (View as DetailView).FindItem("StoppageAmount");
if (_peditor_stoppagerate != null) {
if (obj.StoppageRate == enumStoppageRates.None)
_peditor_stoppagerate.Caption = DevExpress.ExpressApp.Utils.CaptionHelper.GetLocalizedText("eKolayBu_Texts", "LBL_STOPPAGEAMOUNT");
else
if (obj.StoppageRate == enumStoppageRates.s10)
_peditor_stoppagerate.Caption = DevExpress.ExpressApp.Utils.CaptionHelper.GetLocalizedText("eKolayBu_Texts", "LBL_STOPPAGEAMOUNT") + " (%10)";
else
if (obj.StoppageRate == enumStoppageRates.s15)
_peditor_stoppagerate.Caption = DevExpress.ExpressApp.Utils.CaptionHelper.GetLocalizedText("eKolayBu_Texts", "LBL_STOPPAGEAMOUNT") + " (%15)";
else
if (obj.StoppageRate == enumStoppageRates.s17)
_peditor_stoppagerate.Caption = DevExpress.ExpressApp.Utils.CaptionHelper.GetLocalizedText("eKolayBu_Texts", "LBL_STOPPAGEAMOUNT") + " (%17)";
else
if (obj.StoppageRate == enumStoppageRates.s2)
_peditor_stoppagerate.Caption = DevExpress.ExpressApp.Utils.CaptionHelper.GetLocalizedText("eKolayBu_Texts", "LBL_STOPPAGEAMOUNT") + " (%2)";
else
if (obj.StoppageRate == enumStoppageRates.s20)
_peditor_stoppagerate.Caption = DevExpress.ExpressApp.Utils.CaptionHelper.GetLocalizedText("eKolayBu_Texts", "LBL_STOPPAGEAMOUNT") + " (%20)";
else
if (obj.StoppageRate == enumStoppageRates.s3)
_peditor_stoppagerate.Caption = DevExpress.ExpressApp.Utils.CaptionHelper.GetLocalizedText("eKolayBu_Texts", "LBL_STOPPAGEAMOUNT") + " (%3)";
else
if (obj.StoppageRate == enumStoppageRates.s4)
_peditor_stoppagerate.Caption = DevExpress.ExpressApp.Utils.CaptionHelper.GetLocalizedText("eKolayBu_Texts", "LBL_STOPPAGEAMOUNT") + " (%4)";
else
if (obj.StoppageRate == enumStoppageRates.s5)
_peditor_stoppagerate.Caption = DevExpress.ExpressApp.Utils.CaptionHelper.GetLocalizedText("eKolayBu_Texts", "LBL_STOPPAGEAMOUNT") + " (%5)";
}
View view = Frame.View;
if (Frame.SetView(null, true, null, false)) {
view.LoadModel(false);
Frame.SetView(view);
}
}
Hello, Kartal.
It is incorrect to call Frame.SetView from within the ObjectChanged event handler. Frame.SetView is a very serious operation that destroys and recreates the whole View controls and related Controllers. You are trying to do this in the middle of some logic in your custom Controller. So, this glitch is expected with your custom code, especially because you do not commit your existing changes manually and you do not unsubscribe from events. Even if you do commit changes and unsubscribe from events, recreating View controls and Controllers is a very costly operation performance wise (if it is executed on each property change).
We recommend using Frame.SetView only in rare usage scenarios, such as applying Application Model changes to the current View immediately or assigning a new View to an existing window.
Normally, captions are updated when View creates controls for the first time (example). If this does not meet your needs and you require more frequent updates, please describe your usage scenario and expected results from an end-user perspective. With this information, we will be able to find alternative solutions (if possible). It might be possible to achieve your ultimate goal from another perspective with different technical solutions. Thanks.
Hello Dennis,
I want to change view item captions by conditionally. I want to change some property captions when user change some values on a view. Please look at the attached file.
Hello, Kartal. Thank you for your video. Your scenario is now clear and makes sense to me. I hope that we will able to find another solution with direct customization of DxFormLayout items in code or other techniques with JavaScript (rather than setting ViewItem's Caption property). Please bear with us.