Remove Dynamic Properties from SimpleAction

StatusIDPriorityType
Closed33427MajorQuestion
Profile Reply
gabossolo Client

Hi !

Base on the code below, could you please help me on how to remove a selected dynamic property from SimpleAction.

The code used to add a dynamic property :

public AddDynamicPropertyController()
{
InitializeComponent();

var addDynamicProperty =
new SimpleAction(this, "AddDynamicProperty", PredefinedCategory.RecordEdit)
{
Caption = "AddDynamicProperty"
};
addDynamicProperty.Executed += AddDynamicPropertyOnExecuted;
}

private void AddDynamicPropertyOnExecuted(object sender, ActionBaseEventArgs actionBaseEventArgs)
{
if (!(View.CurrentObject is Currency currentObject)) return;
var propertyName = "myDpo" + currentObject.Dpo.DpoProperties.Count;
var objectSpace = Application.CreateObjectSpace();
var myDefaultValueObject = objectSpace.CreateObject();
myDefaultValueObject.Name = propertyName;
myDefaultValueObject.PropertyType = typeof(DateTime); myDefaultValueObject.ValueDateTime = DateTime.Now;
currentObject.AddProperty(myDefaultValueObject.Name, myDefaultValueObject.PropertyType);

objectSpace.CommitChanges();
//currentObject.Session.CommitTransaction();

foreach (var property in currentObject.Dpo.DpoProperties.Values.Where(property =>
property.PropertyType == myDefaultValueObject.PropertyType &&
property.Name == myDefaultValueObject.Name))
{
property.Value = myDefaultValueObject.Value;
}

objectSpace.CommitChanges();

//currentObject.Session.CommitTransaction();

View.ObjectSpace.CommitChanges();
ObjectSpace.Refresh();
}

Replies

User Description Posted On
MariyaVoytovich Agent

Hello gabossolo!

Remove the property you can with help code below:

void remove_Execute(object sender, SimpleActionExecuteEventArgs e)
{
var currentObject = View.CurrentObject as PersistentXafariBaseObject;
var obj = currentObject.DynamicProperties.First(x => x.Name == "NameAction");
currentObject.DynamicProperties.Remove(obj);ObjectSpace.CommitChanges();
View.ObjectSpace.CommitChanges();
ObjectSpace.Refresh();
}

Feel free to contact us if you need further assistance or have additional questions.

Regards,
Mariya
On behalf of Xafari Client Services Team

gabossolo Client

Hi Mariya -- What's "NameAction" ?
And How to get the current selected Dp in Dpo VeticalGrid?

Regards, GB

MariyaVoytovich Agent

Hello gabossolo!

This is an edited code for your question.

private void removeSimpleAction_Execute(object sender, SimpleActionExecuteEventArgs e)
{
var propertyEditor = View.FindItem("Dpo") as Xafari.BC.Win.Editors.DynamicPropertiesEditor;
if (propertyEditor == null) return;
var control = propertyEditor.Control as VGridControl;
if (control == null) return;var currentObject = View.CurrentObject as PersistentXafariBaseObject;
if (!string.IsNullOrEmpty(control.FocusedRow.Properties.FieldName))
{
var obj = currentObject.DynamicProperties.First(x => x.Name == control.FocusedRow.Properties.FieldName);
currentObject.DynamicProperties.Remove(obj);

ObjectSpace.CommitChanges();
View.ObjectSpace.CommitChanges();
ObjectSpace.Refresh();
}
}

Feel free to contact us if you need further assistance or have additional questions.

Regards,
Mariya
On behalf of Xafari Client Services Team

gabossolo Client

Working fine!!!

Thank you very much!

Regards, GB

× This ticket is closed.

Write US