csharp #XAF #XPO如何添加一个Action,它将在单独的ListView中显示已过滤的详细信息集合

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp #XAF #XPO如何添加一个Action,它将在单独的ListView中显示已过滤的详细信息集合相关的知识,希望对你有一定的参考价值。


Jakub Kosinski2 years ago
when i declare few class where one i parent with few childs in detail view i get tabs with child records. I.e customer and child records: orders, invoices , payments. I want to not display child views but want to add extra action for display it using Actions from ribbon

I‍ find description how to display list view using action:

private void simpleAction1_Execute(object sender, SimpleActionExecuteEventArgs e) {     IObjectSpace objectSpace = Application.CreateObjectSpace(typeof(Invoice));     e.ShowViewParameters.CreatedView = Application.CreateListView(objectSpace, typeof(Invoice), true); }

b‍ut there i get all records, but i want only related to customer from DetailView. How to add this filtering ?
Leave a Comment
1 Solution
Andrey K (DevExpress Support)2 years ago
Hello,

To get an object that is currently selected in a view, use the View.CurrentObject property, to apply a filter to a created list view, use its CollectionSourceBase.Criteria property. So the code of your action can look as follows:

[C#]Open in popup window
        private void simpleAction1_Execute(object sender, SimpleActionExecuteEventArgs e) {
            var selectedContact =(Contact) this.View.CurrentObject;
            IObjectSpace objectSpace = Application.CreateObjectSpace(typeof(MyTask));
            var listView= Application.CreateListView(objectSpace, typeof(MyTask), true);
            listView.CollectionSource.Criteria["MyFilter1"]= new BinaryOperator("AssignedTo.Oid", selectedContact.Oid, BinaryOperatorType.Equal);
            e.ShowViewParameters.CreatedView = listView;
        }

To hide an item from a detail view, remove it from the "Views-YourNameSpace-YourClass_DetailView-Items" node's collection using Model Editor.

Let me know if you have any additional questions.

Thanks,
Andrey
Jakub Kosinski2 years ago
Thank for your reply.
B‍ut if i show new window with filter criteria, and try to add new record, then parent is not filled. How to add to this code to fill correct value. I know i can in dataModel set initial values when record is creating, but how to get there accessories to parent record ?

A‍nd one more question: how to force this created view to run in Server mode ? 
Alex Gn (DevExpress)2 years ago
Hello Jakub,

You can modify the controller as follows:

[C#]Open in popup window
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.Model.NodeGenerators;
using MainDemo.Module.BusinessObjects;

namespace MainDemo.Module.Controllers {
    public class OpenListViewController : ViewController<DetailView> {
        private SimpleAction simpleAction1;
        private void SimpleAction1_Execute(object sender, SimpleActionExecuteEventArgs e) {
            IMemberInfo memberinfo = Application.TypesInfo.FindTypeInfo(typeof(Contact)).FindMember("Tasks");
            string viewId = ModelNestedListViewNodesGeneratorHelper.GetNestedListViewId(memberinfo);
            PropertyCollectionSource collectionSource = Application.CreatePropertyCollectionSource(ObjectSpace, typeof(Contact), View.CurrentObject, memberinfo, viewId, CollectionSourceDataAccessMode.Server, CollectionSourceMode.Normal);
            var listView = Application.CreateListView(viewId, collectionSource, false);
            e.ShowViewParameters.CreatedView = listView;
            e.ShowViewParameters.TargetWindow = TargetWindow.NewWindow;
        }
        public OpenListViewController() {
            this.TargetObjectType = typeof(Contact);
            simpleAction1 = new SimpleAction(this, "OpenListView", "Edit");
            simpleAction1.Execute += SimpleAction1_Execute;
        }
    }
}
The LinkNewObjectToParentImmediately property specifies the moment when a new object is added to the parent collection. By default its value is false and you need to commit the master object to save the link to a newly created object.

Let me know if you need any further assistance.

以上是关于csharp #XAF #XPO如何添加一个Action,它将在单独的ListView中显示已过滤的详细信息集合的主要内容,如果未能解决你的问题,请参考以下文章

How to: Use XPO Upcasting in XAF 如何:在 XAF 中使用 XPO 强制转换

XAF-从业务类继承 (XPO)

XAF中多对多关系 (XPO)

XAF-内置初始化数据 (XPO)

XAF-如何实现自定义权限系统用户对象

csharp #LINQ到#XPO