Ticket Q514530
Visible to All Users

How to change a DetailView editor or ListView column caption dynamically

created 12 years ago (modified 6 years ago)

Hello,

please have a look at this method (it is still the long version for debugging):

C#
void Ansicht_ControlsCreated(object sender, EventArgs e) { var LControl = Ansicht.Control as XafLayoutControl; foreach (var Item in LControl.Items) { if (Item is XafLayoutControlGroup) { var LayoutControlGruppe = Item as XafLayoutControlGroup; if (LayoutControlGruppe != null) { foreach (ParalistikBenennungTAB Benennung in Benennungen) { string ModelId = LayoutControlGruppe.Model.Id; string BNennung = Benennung.ParalistikSubGruppeFD; if ( ModelId == BNennung) { if ((!string.IsNullOrEmpty(Benennung.GruppenNameFD)) && (!string.IsNullOrEmpty(Benennung.GruppenNamePluralFD))) { LayoutControlGruppe.Model.Caption = Benennung.GruppenNameFD; if (((LayoutControlGruppe.Model.Id.Contains("Sub") && (!LayoutControlGruppe.Model.Id.EndsWith("Sub")))) || (LayoutControlGruppe.Model.Id == "Bestandteile")) { LayoutControlGruppe.Model.Caption = Benennung.GruppenNamePluralFD; } } else { LayoutControlGruppe.Model.Caption = Benennung.ParalistikSubGruppeFD; } break; } } } } else { if (Item is XafLayoutControlItem) { var LayoutControlItem = Item as XafLayoutControlItem; if (LayoutControlItem != null) { foreach (ParalistikBenennungTAB Benennung in Benennungen) { string ModelId = LayoutControlItem.ViewItem.Id; string BNennung = Benennung.ParalistikSubGruppeFD; if ( ModelId == BNennung) { if (!string.IsNullOrEmpty(Benennung.GruppenNameFD)) { LayoutControlItem.ViewItem.Caption = Benennung.GruppenNameFD; } else { LayoutControlItem.ViewItem.Caption = Benennung.ParalistikSubGruppeFD; } break; } } } } } } Ansicht.Refresh(); }

The first part sets captions of XafLayoutControlGroups, this works perfectly.
The second one should set the captions of XafLayoutControlItems. This works, too - from the views second opening on. The first opening always shows the original captions. Why ?

Thank you
Michael

Comments (1)

    After removing all trash it works perfectly.

    Answers approved by DevExpress Support

    created 12 years ago (modified 3 years ago)

    While I am glad to hear that you have solved this problem, I must say that the cause of this behavior is that you set the caption in the Application Model instead of customizing the caption of the required layout item directly. This occurs because at the moment you customize the control, the View model is already loaded and your model changes will not be taken into account until the underlying control is rendered next time.

    That said, you can consider one of the three techniques to achieve the desired result:
    1.  Customize the application model before the control is created and loaded, e.g. as described at How to change an Application Model option globally or for multiple nodes

    2.  Access and customize the underlying layout control item directly after it was created and initialized with default Application Model settings. See the "Access the Layout Control" section in the View Items Layout Customization help topic and also consider these examples from other users:

    WinForms

    ASP.NET Core Blazor

    ASP.NET WebForms

    3.  If the Application Model was customized after the control was created and loaded, recreate the View controls as per How to: Apply Application Model Changes to the Current View Immediately.

    Search keywords: runtime, title, text, change, modify, update, customize, in code, PropertyEditor, ViewItem, immediately

    See Also:
    How to dynamically change mask settings based on the current object

      Show previous comments (3)
      DevExpress Support Team 12 years ago

        You are always welcome, Michael.

          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); } }
          Dennis Garavsky (DevExpress) 3 years ago

            @Kartal T:URGUT:
            I created a separate ticket on your behalf: T1050385: Blazor - Avoid the "Unsaved changes will be lost…" message when changing ViewItem's Caption at runtime with Frame.SetView. We placed it in our processing queue and will process it shortly.

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.