in
Forums
Blogs
Files
Devexpress.Com
Client Center
Support Center
DevExpress Channel

Accessing Property Editors etc.

Last post 7/12/2007 6:02 AM by M. Mbabu. 7 replies.
Page 1 of 1 (8 items)
Sort Posts:
Previous Next
  • 7/11/2007 3:36 AM

    Accessing Property Editors etc.

    Hi all,

    I have several queries I'd like a little help on.

    1. I would like to enable/disable/hide some property editors depending on whether a DetailView is opened to add a new object

    or is editing an existing object.

    2. I'd like to have my views customized in code e.g. performing the following tasks:
        a) adding a lookup editor to detail view and adding it to the layout.
        b) adding a tabbed group in detail view and rearranging the layout.

    3. I'd like to update one property based on the value of another which gets it value from the database. See commented

    section. Also, I'd like to disable the LotNo property editor if the AutoGenerateLotNo is true (see 1 above), but I cant quite

    get it right.

        [DefaultClassOptions]
        public class Account : BaseObject
        {
            bool mAutoGenerateLotNo;
            [NonPersistent]
            public bool AutoGenerateLotNo
            {
                get { return mAutoGenerateLotNo; }
                set
                {
                    SetPropertyValue("AutoGenerateLotNo", ref mAutoGenerateLotNo, value);

                    if (this.Session.IsNewObject(this) && this.AutoGenerateLotNo)
                    {
                        //Fetch the highest LotNo, increment it by one and assign it
                        //to LotNo i.e. 'Auto-Generate' the number
                    }
                }
            }

            int mLotNo;
            public int LotNo
            {
                get { return mLotNo; }
                set { SetPropertyValue("LotNo", ref mLotNo, value); }
            }


            public override void AfterConstruction()
            {
                base.AfterConstruction();

                this.AutoGenerateLotNo = true;
            }

            public Account() : this(Session.DefaultSession) { }
            public Account(Session session) : base(session) { }

        }

    4. I have the following objects:

        public enum TypeOfAuction { Main, Secondary };

        [DefaultClassOptions]
        public class AuctionType : BaseObject
        {
            DateTime mAuctionDate;
            public DateTime AuctionDate
            {
                get { return mAuctionDate; }
                set { SetPropertyValue("AuctionDate", ref mAuctionDate, value); }
            }

            TypeOfAuction mTypeOfAuction;
            public TypeOfAuction TypeOfAuction
            {
                get { return mTypeOfAuction; }
                set { SetPropertyValue("TypeOfAuction", ref mTypeOfAuction, value); }
            }

            Auction mAuction;
            [Association("Auction.AuctionType", typeof(Auction))]
            public Auction Auction
            {
                get { return mAuction; }
                set { SetPropertyValue("Auction", ref mAuction, value); }
            }

            public AuctionType() : this(Session.DefaultSession) { }
            public AuctionType(Session session) : base(session) { }

        }

        [DefaultClassOptions]
        public class Auction : BaseObject
        {

            [Custom("Caption", "Auction Types")]
            [Association("Auction.AuctionType"), Aggregated]
            public XPCollection<AuctionType> AuctionTypeCollection
            {
                get { return GetCollection<AuctionType>("AuctionTypeCollection"); }
            }

            public Auction() : this(Session.DefaultSession) { }
            public Auction(Session session) : base(session) { }

        }

    I would like each AuctionType in Auction to be unique i.e. for each TypeOfAuction (enum) value there should be only one

    AuctionType and All enum values should be represented. How do I build this criteria?


    How do I go about achieving all these? Any help would be greatly appreciated.
       

    Regards,

    Keith. 

  • 7/11/2007 4:40 AM In reply to

    Re: Accessing Property Editors etc.

    1. Well, I've recently implemented similar functionality. That's all I can answer at this moment, quite busy today Stick out tongue

    private void ContactController_Activated(object sender, EventArgs e){
      View.ControlsCreated += new EventHandler(View_ControlsCreated);
    }

    void View_ControlsCreated(object sender, EventArgs e){
      DetailView dv = (DetailView)base.View;
      Contact
    contact = (Contact)dv.CurrentObject;

      // if object is new we do nothing
     
    if (base.ObjectSpace.Session.IsNewObject(contact)) return;  
      
      
      foreach (DetailViewItem dvi in dv.Items){
        switch (dvi.Id){
          case "ContactID": //property name for which editor should be disabled
            if (dvi.Control is StringEdit){
            StringEdit control = dvi.Control as StringEdit;
            control.Enabled =
    false;
            }
          break;
          //other fields processing

        }
      }
    }

  • 7/11/2007 9:05 AM In reply to

    Re: Accessing Property Editors etc.

    Thanks Michal (as always Smile). I was busy implementing your solution. My bad though. I hadn't gone through the entire documentation. The example is actually there.

    Regards,

    Keith. 

  • 7/11/2007 9:53 AM In reply to

    Re: Accessing Property Editors etc.

    Keith, I just found, that it is not enough to subscribe to View.ControlsCreated. You need to "attach" to View.CurrentObjectChanged (because of Move next/previous Actions) and ObjectSpace.ObjectSaved (because when user saves the object - it becomes saved and editor should be disabled).

    I belive that somewere out there could be more elegant solution...Wink

    Regards,
    Michal

  • 7/11/2007 10:28 AM In reply to

    Re: Accessing Property Editors etc.

    Yeah, I've also just found out you need to do more to achieve some effects. Let's see how it works. Any chance you might find time to help on the other issues?

    Keith. 

  • 7/11/2007 12:08 PM In reply to

    Re: Accessing Property Editors etc.

    I try to find more time today, but that are my first thoughts:

    2. I would try to edit view model nodes (layout nodes) and then synchronize it with the view (I've never tried it with the layout). Do you want to do customizations just when opening the view (once) or continuously per active object?
    Have in mind that there are much more advanced users than me is this forum, I'm not sure if it is a proper way, but I'll try to implement it... You have been warned Stick out tongue

    3. Enabling/disabling is similar to 1. you could subscribe EditValueChanged event of editor control. But your approach in auto-incrementing LotNo could cause some problems in multiuser enviroment. Try using DevExpress.Persistent.BaseImpl.DistributedIdGeneratorHelper.

    Regards,
    Michal

  • 7/12/2007 3:14 AM In reply to

    Re: Accessing Property Editors etc.

    4. Validation

    [System.ComponentModel.

    Browsable(false)]
    [
    RuleFromBoolProperty("Auction.AuctionTypeCollection.Unique", DefaultContexts.Save, "Auction type entries must be unique and must use all TypeOfAuction.")]
    public bool IsValid{
      get{
        Array enumVaules = Enum.GetValues(typeof(TypeOfAuction));
        int individualValues = enumVaules.Length;

        //count must be equal
        int rowsCount = AuctionTypeCollection.Count;
        if (rowsCount != individualValues) return false;

        //test for duplicates
        List<TypeOfAuction> foundValues = new List<TypeOfAuction>();
        foreach (AuctionType at in AuctionTypeCollection){
          if (!foundValues.Contains(at.TypeOfAuction)){
            foundValues.Add(at.TypeOfAuction);
          }
    else {
        
        //if type is already on the list - it is a duplicate
            return false;
          }
        }
        return true;
      }
    }

    Regards,
    Michal

    Filed under:
  • 7/12/2007 6:02 AM In reply to

    Re: Accessing Property Editors etc.

    4. Validation

    This works perfectly. I had to split it into two though, row count for the master and unique for the child. Thanks.

    Regards,

    Keith. 

Page 1 of 1 (8 items)
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED