Operation is not valid due to the current state of the object Error.. - InfoPath Dev
in

InfoPath Dev

Operation is not valid due to the current state of the object Error..

Last post 09-04-2010 01:57 AM by Qazi Anis. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 08-20-2010 12:39 AM

    Operation is not valid due to the current state of the object Error..

    I have wrote code for getting dropdown based value from Sharepoint list.

    But it give me error Operation is not valid due to the current state of the object when i set it to textbox.

    Please take look of my code.

     

      public void group2_Validating(object sender, XmlValidatingEventArgs e)
            {
                // Write your code here.
                XPathNavigator elementddlCostCenter = this.MainDataSource.CreateNavigator().SelectSingleNode("//my:myFields/my:group1/my:group2/my:ddlFirstName", this.NamespaceManager);

                string ddlDepartedFrom = elementddlCostCenter.Value;

                XPathNavigator elementddlArrivalAt = this.MainDataSource.CreateNavigator().SelectSingleNode("//my:myFields/my:group1/my:group2/my:ddlLastName", this.NamespaceManager);

                string ddlArrivalAt = elementddlArrivalAt.Value;

                if (ddlDepartedFrom != null && ddlDepartedFrom != "" && ddlArrivalAt != null && ddlArrivalAt != "")
                {
                    // ListWebServices.Lists listServices = new ListWebServices.Lists();



                    SPQuery qry = new SPQuery();

                    string camlquery = "<Where><And><Eq><FieldRef Name='Title' /><Value Type='Text'>" + ddlDepartedFrom + "</Value></Eq>" + "<Eq><FieldRef Name='Categories' /><Value Type='Text'>" + ddlArrivalAt + "</Value></Eq></And></Where>";
                    // string camlquery = "<Where><Eq><FieldRef Name='Categories'/><Value Type='Text'>"+ ddlArrivalAt +"</Value></Eq></Where>";
                    qry.Query = camlquery;
                    SPSite site = null;
                    SPWeb web = null;

                    try
                    {
                        
                        SPSecurity.RunWithElevatedPrivileges(
                        delegate()
                        {

                            string m_sharepointUrl = "http://ProductionServer";
                            using (site = new SPSite(m_sharepointUrl))
                            {
                                if (site != null)
                                {

                                    using (web = site.OpenWeb())
                                    {
                                        SPList list = web.Lists["Age"];

                                        if (list != null)
                                        {
                                            DataTable _table = new DataTable();
                                            DataColumn dc = new DataColumn("Mileage");
                                            _table.Columns.Add(dc);
                                            SPListItemCollection listItemsCollection = list.GetItems(qry);
                                            foreach (SPListItem item in listItemsCollection)
                                            {
                                                DataRow _row = _table.NewRow();
                                                _row[0] = SPEncode.HtmlEncode(item["Age"].ToString());
                                                Milage = Convert.ToInt32(SPEncode.HtmlEncode(item["Age"].ToString()));
                                                //Mileage = Convert.ToInt32(_row[0].ToString());
                                                _table.Rows.Add(_row);

                                            }

                                            XPathNavigator domNav = MainDataSource.CreateNavigator();
                                            string xhtmlRTFField = domNav.SelectSingleNode("//my:myFields/my:group1/my:group2/my:txtAge", NamespaceManager).InnerXml;

                                             domNav.SelectSingleNode("//my:myFields/my:group1/my:group2/my:txtAge", NamespaceManager).InnerXml = Milage.ToString(); ---> I got error here
                                            //domNav.SelectSingleNode("//my:myFields/my:group1/my:group2/my:txtAge", NamespaceManager).SetValue(Milage.ToString());
                                        }
                                        web.Close();
                                    }
                                    site.Close();
                                }
                            }

                        }
                            );
                    }
                    catch (Exception ex)
                    {
                    }
                    
                }
            }

     

     

    Please help on this.

    Thank you.

    Bhavin A Sankhat
    Filed under:
  • 09-04-2010 01:57 AM In reply to

    Re: Operation is not valid due to the current state of the object Error..

    on validating event you cant set value to the field being validated, or if it is a group you cant set value to any of the fields inside the group.

    Qazi Anis
    Technical Architect
    Bitwise Inc
Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.