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
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 savedhow to disable certain actions for a new record
Answers approved by DevExpress Support
Hello Martin,
I see two good solutions for you:
- 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. - 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
Hi, this is still a solution for the problem?
Or there is another way?
Thanks,
Paolo
@Paolo:
Yes, these are possible recommended solutions. Let us know in case of any difficulties with them.