Hello
In my XAF application I have defined some persistent object. I want one of its fields to be atypically formatted everywhere it's displayed (it's read only), so on all lists and detail views. I implemented custom formatter as described in documentation , then I wrote property editor and assigned it to field in BOModel->MyObject->OwnMembers->MyField->PropertyEditorType.
C#[PropertyEditor(typeof(Int16), false)]
public class MyPropertyEditor : DXPropertyEditor
{
public MyPropertyEditor(Type objectType, IModelMemberViewItem model) : base(objectType, model)
{
}
protected override object CreateControlCore()
{
return new SpinEdit();
}
protected override RepositoryItem CreateRepositoryItem()
{
return new RepositoryItemSpinEdit();
}
protected override void SetupRepositoryItem(RepositoryItem item)
{
base.SetupRepositoryItem(item);
item.DisplayFormat.FormatType = FormatType.Custom;
item.DisplayFormat.Format = new MyFormatter();
item.DisplayFormat.FormatString = MyFormatter.MY_FORMAT;
}
}
This works fine, but the problem appears when I want to use different formatting depending on another field value. I found that for DetailView I can use CurrentObject property:
C#int anotherField = ((MyObject)CurrentObject).AnotherField;
switch (anotherField)
{
case 0:
item.DisplayFormat.FormatString = MyFormatter.MY_FORMAT_A;
break;
case 1:
item.DisplayFormat.FormatString = MyFormatter.MY_FORMAT_B;
break;
default:
item.DisplayFormat.FormatString = MyFormatter.MY_FORMAT_C;
break;
}
But this doesn't work with ListView - CurrentObject is null. Is there some way to get my solution working also on lists, or some totally different approach is more suitable here?
I use DevExpress 10.1.8.
Karol