Ticket CQ38893
Visible to All Users

How to pass PropertyCollectionSource as CollectionSource for PopupWindowShowAction

created 18 years ago

Hello,
how to pass a XPCollection as CollectionSource is clear for me, but …
I cannot use the same for a NonPersitent object
[NonPersistent]
class : BaseObject
You are using a PropertyCollectionSource for those property types within a persistent object.
So I tried it also, but have been stopped by the ComplexMemberDescriptor.
Could you explain how to use such classes for PopupWindowShowAction or in general, how to manually create a listview based on such objects? I mean, how to define the CollectionSource for those types of objects?
Thank you
Bernd

Comments (3)
DevExpress Support Team 18 years ago

    Hi,
    You should use the "ObjectSpaceInMemory" class if you want to work with a non-persistent objects.
    For example, you can create a DetailView:
    ObjectSpaceInMemory objectSpace = new ObjectSpaceInMemory();
    Manager.CreateDetailView(objectSpace, new MyNonPersistentObject(objectSpace.Session), false);
    or simply a CollectionSource:
    ObjectSpaceInMemory objectSpace = new ObjectSpaceInMemory();
    MyNonPersistentObject obj = new MyNonPersistentObject(objectSpace.Session);
    obj.Save();
    CollectionSource collectionSource = new CollectionSource(objectSpace, typeof(MyNonPersistentObject));
    The ObjectSpaceInMemory class uses an instance of the DataSet class to store all the objects in memory, so you can work with it in the usual way.
    But note, that in any case your class should be marked with the NonPesistent attribute: this is the core requirement to show an object in XAF.
    I've noted that this answer is not exactly the subject of your question. Does it help you?
    Thanks,
    Plato

      Hi Plato,
      actually it's exactly the answer I needed, so I guess the subject is incorrect.
      But, when I use:
      ObjectSpaceInMemory objectSpace = new ObjectSpaceInMemory();
      e.ShowViewParameters.CreatedView = Manager.CreateListView(Manager.FindListViewID(typeof(MyNonPersistentObject)), new CollectionSource(objectSpace, typeof(MyNonPersistentObject)), false);
      the error
      "While resolving the real objects type, a reference to an abstract class … found" occurs.
      After that the windows gets opened. So I see the view I wanted, but cannot add any objects to the collection.
      My class is declared as:
      [NonPersistent]
      public class MyNonPersistentObject : BaseObject
      It would be great if we could solve this problem too.
      Thanks a lot
      Bernd

      DevExpress Support Team 18 years ago

        Hi,
        At the moment it is impossible to show a ListView in such a manner.
        I suggest that you show an object with a collection property (but note, that in this case you may need to provide some additional code, for example, you may need to implement the INotifyPropertyChanged interface and use the BindingList<T> class):

        C#
        [NonPersistent] public class MyNonPersistentObject { public MyNonPersistentObject(string subject) { this.Subject = subject; } private string subject; public string Subject { get { return subject; } set { subject = value; } } private BindingList<MyNonPersistentObjectItem> items = new BindingList<MyNonPersistentObjectItem>(); [Aggregated] public BindingList<MyNonPersistentObjectItem> Items { get { items.AllowNew = true; return items; } } } [NonPersistent] public class MyNonPersistentObjectItem : INotifyPropertyChanged { private string itemName; public MyNonPersistentObjectItem(Session session) { } public string ItemName { get { return itemName; } set { itemName = value; OnPropertyChanged("ItemName"); } } protected void OnPropertyChanged(string propertyName) { if(PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } public event PropertyChangedEventHandler PropertyChanged; } public class MemoryCollectionController : ViewController { private SimpleAction action; public MemoryCollectionController() { action = new SimpleAction(this, "ShowMem", "View"); action.Execute += new SimpleActionExecuteEventHandler(action_Execute); TargetViewNesting = Nesting.Root; } protected override void OnActivated() { base.OnActivated(); } void action_Execute(object sender, SimpleActionExecuteEventArgs e) { ObjectSpaceInMemory objectSpace = new ObjectSpaceInMemory(); e.ShowViewParameters.CreatedView = Manager.CreateDetailView(objectSpace, new MyNonPersistentObject("123"), false); e.ShowViewParameters.TargetWindow = TargetWindow.Modal; } }

        Thanks,
        Plato

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.