Ticket Q536551
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

How to change a DetailView editor or ListView column caption dynamically

Win - change property editor's caption at runtime

created 11 years ago

Hi!

I'm trying to change property caption based on current object's values.

I've found this ticket: http://www.devexpress.com/Support/Center/Question/Details/Q407697

Older tickets seems to be out-dated since they use View.SyncronizeWithInfo() which doesn't seems exists any more.

Here is my controller that should change caption and AllowEdit:

C#
private DetailView detailView { get { return View as DetailView; } } public SkriptaStavka_Controller() { InitializeComponent(); RegisterActions(components); TargetObjectType = typeof(SkriptaStavka); } protected override void OnActivated() { base.OnActivated(); if (detailView != null && detailView.ViewEditMode == ViewEditMode.Edit) { SkriptaStavka ss = detailView.CurrentObject as SkriptaStavka; ss.Changed += ss_Changed; } } void ss_Changed(object sender, DevExpress.Xpo.ObjectChangeEventArgs e) { if (e.PropertyName == "TipStavke") { SkriptaStavka ss = e.Object as SkriptaStavka; PropertyEditor v1 = detailView.FindItem("Vrijednost") as PropertyEditor; PropertyEditor v2 = detailView.FindItem("Vrijednost2") as PropertyEditor; PropertyEditor v3 = detailView.FindItem("VrijednostS") as PropertyEditor; if (ss.TipStavke != null) { v1.Caption = String.IsNullOrWhiteSpace(ss.TipStavke.NaslovVrijednost1) ? "Vrijednost 1" : ss.TipStavke.NaslovVrijednost1; v1.AllowEdit["Naslov"] = !String.IsNullOrWhiteSpace(ss.TipStavke.NaslovVrijednost1); v2.Caption = String.IsNullOrWhiteSpace(ss.TipStavke.NaslovVrijednost2) ? "Vrijednost 2" : ss.TipStavke.NaslovVrijednost2; v2.AllowEdit["Naslov"] = !String.IsNullOrWhiteSpace(ss.TipStavke.NaslovVrijednost2); v3.Caption = String.IsNullOrWhiteSpace(ss.TipStavke.NaslovVrijednost3) ? "Vrijednost 3" : ss.TipStavke.NaslovVrijednost3; v3.AllowEdit["Naslov"] = !String.IsNullOrWhiteSpace(ss.TipStavke.NaslovVrijednost3); } else { v1.Caption = "Vrijednost 1"; v1.AllowEdit["Naslov"] = false; v2.Caption = "Vrijednost 2"; v2.AllowEdit["Naslov"] = false; v3.Caption = "Vrijednost 3"; v3.AllowEdit["Naslov"] = false; } } } protected override void OnViewControlsCreated() { base.OnViewControlsCreated(); } protected override void OnDeactivated() { if (detailView != null && detailView.ViewEditMode == ViewEditMode.Edit) { SkriptaStavka ss = detailView.CurrentObject as SkriptaStavka; ss.Changed -= ss_Changed; } base.OnDeactivated(); }

Also, SkriptaStavke.TipStavke has ImmediatePostData attribute.

But Caption nor AllowEdit doesn't change. It seems it's changed inside model and it's visible if I close and reopen DetailView.
What am I doing wrong?

Thanks,

Mario

Answers approved by DevExpress Support

created 11 years ago (modified 8 years ago)

Hello Mario,
This code works only for boolean property editors, because their caption is automatically synchronized with the control's caption. To change captions of other property editors, use the following code (a reference to the DevExpress.XtraLayout assembly is required):

C#
void ObjectSpace_ObjectChanged(object sender, ObjectChangedEventArgs e) { if (e.Object == View.CurrentObject && e.PropertyName == "Caption" && e.NewValue != e.OldValue) { WinPropertyEditor amountItem = ((DetailView)View).FindItem("Amount") as WinPropertyEditor; if (amountItem != null) { amountItem.Caption = (String)e.NewValue; ((LayoutControl)View.Control).GetItemByControl(amountItem.Control).Text = amountItem.Caption; } } }
    Show previous comments (2)

      I have this working once the view is up and the user changes values that need to trigger caption changes.

      However, when my detailview is activated I want it to run this code to set the caption based on the existing values of the currrentobject.  I can't find an an appropriate event to call this because GetItemByControl fails to locate the item, I assume because the layout item collection isn't loaded yet?

        Nevermind… just going to use statictextviewitem in place of actual property caption

        Anatol (DevExpress) 8 years ago

          Yes, this approach cannot be used to change the initial caption. You can use the WinLayoutManager.ItemCreated event to accomplish this task, as shown in the display a field as bold ticket.

          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.