v
Not logged inv
SearchAsk a QuestionReport an IssueMake a SuggestionMy Questions and Issues
Issue Details
Find By ID

DetailView set property editor read only on business rule

Issue Details

Log in to Track Changes or Edit
Q207231
Question
glynn davies
Yes
Processed
Insufficient Information
.NET (Frameworks)
eXpressApp Framework
V9.0
Windows XP
Microsoft Visual Studio 2005
5/28/2009 6:21:55 PM
-> Reviewed by DevExpress Team 5/27/2009 11:14:58 AM
-> Created by glynn davies 5/27/2009 11:19:52 AM

Hi,

Before I stop work and use the modules provided by Dennis as part of K18163 can you tell me why my DetailView controller doesn't work reliably. It seems to work sometimes but not others, the code is shown below and i'm trying to make the "ExpiryDate" readonly when "Enabled" is false.

Thanks

Glynn

 public partial class DocumentDetailViewController : ViewController
    {
        private DetailView detailViewCore = null;
        private Dictionary<string,PropertyEditor> editorsHolder = new Dictionary<string,PropertyEditor>();

        public DocumentDetailViewController()
        {
            TargetViewType = ViewType.DetailView;
            TargetObjectType = typeof(Document);

            InitializeComponent();
            RegisterActions(components);
        }

        protected override void OnActivated()
        {
            base.OnActivated();
           
            View.ControlsCreated += new EventHandler(View_ControlsCreated);
            View.CurrentObjectChanged += new EventHandler(View_CurrentObjectChanged);
            View.ObjectSpace.ObjectChanged += new EventHandler<ObjectChangedEventArgs>(ObjectSpace_ObjectChanged);

            detailViewCore = (DetailView)View;
        }

        protected override void OnDeactivating()
        {
            base.OnDeactivating();
            View.ControlsCreated -= new EventHandler(View_ControlsCreated);
            View.CurrentObjectChanged -= new EventHandler(View_CurrentObjectChanged);
            View.ObjectSpace.ObjectChanged -= new EventHandler<ObjectChangedEventArgs>(ObjectSpace_ObjectChanged);
        }

        private PropertyEditor Initialise(string name)
        {
            PropertyEditor editor = null;
            try
            {
                editor = editorsHolder[name];
            }
            catch (KeyNotFoundException)
            {
                editor = (PropertyEditor)detailViewCore.FindItem(name);
                if (editor != null)
                {
                    editorsHolder.Add(name, editor);
                }
                else
                {
                    throw new Exception(string.Format("Cannot find property editor for the following property: {0}", name));
                }
            }
            return editor;
        }

        void ObjectSpace_ObjectChanged(object sender, ObjectChangedEventArgs e)
        {
            if(e.PropertyName=="Enabled")
            {
                UICustomisation();
            }
        }

        void View_CurrentObjectChanged(object sender, EventArgs e)
        {
            UICustomisation();
        }

        void View_ControlsCreated(object sender, EventArgs e)
        {
            UICustomisation();
        }
      

        private void UICustomisation()
        {
            Document obj = (Document)View.CurrentObject;
            PropertyEditor editor = Initialise("ExpiryDate");

            editor.ReadOnly.SetItemValue("Expiry read only", !obj.Enabled);
        }
    }

<- Processed (Answered) by DevExpress Team 5/27/2009 11:31:53 AM

Hello Glynn,

No, I cannot. This code is outdated, and I strongly recommend that you use the modules I provided in the KB. They work fine, and I tested them in many scenarios.

Also, could you please elaborate more on this:
>>
 It seems to work sometimes but not others,
<<
It would be good if you could use the modules and test them in the scenarios that you think may not work or do not work steadily. I will be glad to research them. Thanks for your help in advance.

Thanks,
Dennis

-> Reactivated by glynn davies 5/27/2009 11:51:23 AM

Hi Dennis,

OK, I'll use your modules, they look great.

It would have been nice however to understand why the code didn't work because I followed a previous sample and I understood what it is was trying to do.

That's my only issue with XAF, it makes lots of things easy but because you take alot of the high level functionality for granted you end up not fully understanding the basics.

Thanks

Glynn

<- Updated by DevExpress Team 5/28/2009 12:24:30 PM

Hello Glynn,

Thanks for the update and sorry for the delay in responding. I am testing your code and will get back to you as soon as I can.

Thanks,
Dennis

<- Processed (Insufficient Information) by DevExpress Team 5/28/2009 6:21:55 PM

Attachment: dxSampleQ207231.zip (31557 bytes)

Hello Glynn,

>>
It seems to work sometimes but not others
...
why the code didn't work
...
<<
I have attached a small sample using the code above. I could not find scenarios where it did not work. Probably, you can tell me the exact steps required to reproduce the problems.

Thanks,
Dennis

Log in to Track Changes or Edit

Peer-to-Peer Discussion in DevExpress Forums

No discussion on this article has been started yet.

Please login to start discussion.

v
v
Search
Searching Tips