How to set the read-only attribute of a certain field from the code behind - InfoPath Dev
in

InfoPath Dev

How to set the read-only attribute of a certain field from the code behind

Last post 12-07-2007 02:07 AM by jaumedejuan. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 12-06-2007 08:18 AM

    How to set the read-only attribute of a certain field from the code behind

    Hi all, 

    I am still in my first Infopath days and I would like to share this issue with you.
    I have a form that is divided in three different sections that will automatically set their fields to read-only, depending on a combination of the current user and other fields that may have been filled in previously.

    So far this is working but I have had to add a pretty big number of "conditional formatting" rules that will make the form not particularly easy to maintain.
    What I would like to do is to control what controls are set to read only from the code behind itself.

    I've seen that I can access the XML nodes via

     XPathNavigator MainDataSource.SelectSingleNode(path,NamespaceManager);

    And that's fine, I've been reading/writing their values with no further issues, but still I have not found out how can I set the value of the read-only attribute to "true".

    Could you please let me know how could I get this done?

     Thanks a lot,

     Jaume

     

     

     

  • 12-06-2007 02:28 PM In reply to

    Re: How to set the read-only attribute of a certain field from the code behind

    Typically what I do is have read-only views and edit views. Then you can use conditions to pick the view. Since you have multiple sections and levels or read-only their may not be anyway around it. In that scenario, if you have say four different levels of user then you create a flag field that will have 1 through four.  When the form opens you determine the user and scenario and set the flag to 1 through 4. Then all of your other rules are built off of what the flag value is.  That is usually the simplest way to handle lots of rule checks like this. 

     If you are using Infopath 2007 you can make a view read-only with one click in view properties. Create the edit view and then just copy it and mark the second read-only.

    I believe in code you have to use the syntax  true() to set an attribute value.

    Hope this helps.

  • 12-07-2007 02:07 AM In reply to

    Re: How to set the read-only attribute of a certain field from the code behind

    I am using Infopath 2007 but as you point out "views" do not seem to be the solution, since they only allow to change the read-only status of the full form instead of just some specific fields.

    I've been considering the flags system that you mention but I have not really seen an actual mechanism within Infopath that allows to do such a thing.
    That got me thinking and I understood that I could set a field as that status flag, with values such as {1,2,3,4} and than add the very same conditional rule to each field, which would call a method that'll retrieve the status that applies.

    I guess that could work better and clear out the code since all the calls from within the form will be exactly the same ones. 

    And with this bit I am kind of lost

    Clay Fox:
    I believe in code you have to use the syntax  true() to set an attribute value.

    Do you mean that it is actually possible to set the value of the read-only attribute? what would be the method/call like?
     

    Clay Fox:
    Hope this helps.

    very helpful indeed 

Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.