Ticket Q399803
Visible to All Users
Duplicate

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

Filtering - Create a built-in criteria function to check if an XPO object is new or saved

how to disable certain actions for a new record

created 13 years ago

Hi,
I have an Object on which I have defined some (simple/popup etc.) actions in several viewcontrollers. These actions must be disabled initially until the Object has been saved for the first time. I now have a NonPersistent field like:
        [NonPersistent]
        [Browsable(false)]
        public int NwProject
        {
            get { return _NwProject; }
            set { SetPropertyValue("NwProject", ref _NwProject, value); }
        }
In the after construction event of the Object I set NwProject to 1 so I can check wether or not this is a new Object in the TargetObjectsCriteria. However I have to enter the criterium by hand (it does not show up in the filter editor) and it looks to me like a bit of a workaround. Is there a better way to test wether or not an Object is new and an Action should be (dis)-abled?
regards,
Martin

Answers approved by DevExpress Support

created 13 years ago (modified 12 years ago)

Hello Martin,
I see two good solutions for you:

  1. Check whether the key property is assigned or not (you can check this either in the TargetObjectsCriteria property for your Action or in an Appearance rule).
    It will suffice your needs if you do not use the BaseObject.OidInitializationMode.AfterConstruction.
  2. Use the IsNewObject method provided by the Session/ObjectSpace types. For instance:
C#
public bool IsSavedObject { get { return !Session.IsNewObject(this); } }

Alternatively, you can implement a custom ViewController and hide a required Action manually. Refer to the How to remove or hide (deactivate, disable) a button ( Action ) from tool bar KB Article for more details.
Let me know in case of any further difficulties.
Thanks,
Dennis

News, tips & tricks and other interesting information about DevExpress Application Framework and ORM

    Comments (2)

      Hi, this is still a solution for the problem?
      Or there is another way?
      Thanks,
      Paolo

      Dennis Garavsky (DevExpress) 12 years ago

        @Paolo:
        Yes, these are possible recommended solutions. Let us know in case of any difficulties with them.

        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.