Assistance with storing different types of objects using FormState - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Assistance with storing different types of objects using FormState

Last post 06-30-2011 08:58 AM by California_Developer. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 06-28-2011 08:23 AM

    Assistance with storing different types of objects using FormState

    Forum Community,

     

    Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman","serif";}

    I’ve run into a problem with the use of the FormState object, and I was hoping someone in the forum could offer some assistance in the matter. The property defining my FormState dictionary object is listed below:

    private Hashtable _VehicleLicense

            {

                get

                {

                    return (Hashtable)FormState["_VehicleLicense"];

                }

                set

                {

                    FormState["_VehicleLicense"] = value;

                }

            }

     

    I created a method that will set the FormState dictionary object; I plan to use a license plate number for the key and a corresponding integer value. The method definition is listed below:

    public void P2p_LI_EquipmentLicenseNumber_Changed(object sender, XmlEventArgs e)

            {

                String engine = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:P2p_LI_EquipmentLicenseNumber", NamespaceManager).Value;

                //Code for setting the FormState object goes here.

            }

     

    My previous code was erroneously invoking the “get” rather than the “set” method. I’ve tried a number of variations to invoke the set method but have been unsuccessful. Once my dictionary object has been successfully set, I plan to update the dictionary object for a license plate using code similar to that shown below:

    if(hashtable.Contains[key]))

    {

          Hashtable[key] = value

    }

     

    Thanks in advance for your assistance; I sincerely appreciate it :-)

     

    ~W

     

  • 06-28-2011 09:57 AM In reply to

    Re: Assistance with storing different types of objects using FormState

    Typically, the set accessor is only invoked in a statement that assigns directly to the property, as in:

    _VehicleLicense = new Hashtable();

    _VehicleLicense = otherHashtable;

    Anything that accesses the property's fields, methods, or indexers, even within an assignment statement, will use the get accessor, as the property's value needs to be retrieved before those operations can be performed.

    One workaround is to have the get accessor ensure that the FormState is initialized before returning:

    private Hashtable _VehicleLicense
            {
                get
                {
                    if(FormState["_VehicleLicense"] == null)
                    {
                       FormState["_VehicleLicense"] = new HashTable();
                    }

                    return (Hashtable)FormState["_VehicleLicense"];
                }
                set
                {
                    FormState["_VehicleLicense"] = value;
                }
            }

     

    how's that?

     

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 06-28-2011 10:08 AM In reply to

    Re: Assistance with storing different types of objects using FormState

     Hi Jimmy,

     

    I have a method named " Normal 0 false false false EN-US X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman","serif";} voidP2p_LI_EquipmentLicenseNumber_Changed()". How would I add a hashtable value (i.e. license plate#) to the FormState object from within my method based on the code sample you provided in your forum reply?

     

    Thanks,

     

    ~W

  • 06-28-2011 10:16 AM In reply to

    Re: Assistance with storing different types of objects using FormState

    If you make the change I showed, you can access the hashtable just like any other hashtable:

    _VehicleLicense["803-445"] = "yes";

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 06-28-2011 10:31 AM In reply to

    Re: Assistance with storing different types of objects using FormState

     Thanks Jimmy; that works :-)

  • 06-30-2011 08:58 AM In reply to

    Re: Assistance with storing different types of objects using FormState

     Hi Jimmy,

     

    You've always given me good advice regarding InfoPath. Could you please take a look at the threat I posted this morning when you have a moment? I'm having trouble getting the "date/time picker" to display military time.The URL for my forum thread is listed below:

    http://www.infopathdev.com/forums/p/19591/67939.aspx#67939

     

    Thanks in advance for your assistance,

     

    ~W

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