This example creates a pop-up window that allows users to perform a custom object search.
-
Create a non-persistent class with properties used to search persistent objects.
File to review: MySearchClass.cs[DomainComponent] public class MySearchClass : NonPersistentBaseObject { [XafDisplayName("FirstName contains:")] public string FirstName { get; set; } [XafDisplayName("Age is equal to:")] public int Age { get; set; } // ... }
-
Add a collection of persistent objects that contains the search results.
File to review: MySearchClass.cs[DomainComponent] public class MySearchClass : NonPersistentBaseObject { // ... private IList<Contact> _contacts = new List<Contact>(); [XafDisplayName("Results:")] public IList<Contact> Contacts { get { return _contacts; } } }
-
Add the MySearch action that populates the collection. File to review: MySearchController.cs
public class MySearchController : ObjectViewController<DetailView, MySearchClass> { public MySearchController() { var myAction1 = new SimpleAction(this, "MySearch", "MySearchCategory"); myAction1.Execute += MyAction1_Execute; } // ... }
-
When a user clicks the MySearch action, create a criterion based on the properties described in the first step and get persistent objects that fit this criterion.
File to review: MySearchController.cspublic class MySearchController : ObjectViewController<DetailView, MySearchClass> { // ... private void MyAction1_Execute(object sender, SimpleActionExecuteEventArgs e) { var mySearchObject = (MySearchClass)View.CurrentObject; var persistentOS = Application.CreateObjectSpace(typeof(Contact)); var criterion = CriteriaOperator.FromLambda<Contact>(x => x.FirstName.Contains(mySearchObject.FirstName) || x.Age == mySearchObject.Age); var results = persistentOS.GetObjects<Contact>(criterion); mySearchObject.SetContacts(results); } }
-
Create the MyShowSearchAction to display the MySearchClass detail view from the Contact list view in a pop-up window. File to review: MyShowSearchController.cs
public class MyShowSearchController : ObjectViewController<ListView, Contact> { public MyShowSearchController() { var mypopAction1 = new PopupWindowShowAction(this, "MyShowSearchAction", PredefinedCategory.Edit); mypopAction1.TargetViewNesting = Nesting.Root; mypopAction1.CustomizePopupWindowParams += MyAction1_CustomizePopupWindowParams; } private void MyAction1_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e) { var nonPersistentOS = (NonPersistentObjectSpace)Application.CreateObjectSpace(typeof(MySearchClass)); var persistentOS = Application.CreateObjectSpace(typeof(Contact)); nonPersistentOS.AdditionalObjectSpaces.Add(persistentOS); var obj = nonPersistentOS.CreateObject<MySearchClass>(); nonPersistentOS.CommitChanges(); var view = Application.CreateDetailView(nonPersistentOS, obj); e.View = view; } }
- Non-Persistent classes
- How to: Show Persistent Objects in a Non-Persistent Object's View
- How to: Include an Action to a Detail View Layout
- Create, Read, Update and Delete Data
- Ways to Show a View
(you will be redirected to DevExpress.com to submit your response)