Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7601735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:14:10+00:00 2026-05-30T23:14:10+00:00

I have a data entry form with many textbox’s and some dropdowns for the

  • 0

I have a data entry form with many textbox’s and some dropdowns for the user to input data. When the user selects a “Location” from the dropdownlist, they can click a button on top of the form to view a popup with more details according to that location. The data successfully automates when the popup loads but when the user tries to close the popup and continue with the main form, an unhandled exception occurs for the system.InvalidOperationException. The error specifically occurs because “The collection I’m Enumerating through has been changed”. Although I’m not changing anything I guess something behind the scenes is happening, here is my code to retreive the data:

        string postalCode;
        string phone1;
        string phone2;
        string supervisor;

        var ObjectContext = new ObjectContext();

        var qry = (from i in ObjectContext.TableLocation
                   where i.LocationName == LocationValue
                   select i).ToList();

        foreach (var data in qry)
        {
           postalCode = data.postalCode;
           phone1 = data.phoneNumber1;
           phone2 = data.phoneNumber2;
           supervisor = data.supervisor
        }

        txtPostalCode.Text = postalCode;
        txtPhone1.Text = Phone1;
        txtPhone2.Text = Phone2;
        txtSupervisor.Text = supervisor;

The LocationValue is linked to a Public variable that the parent form fills with whatever is selected in the location dropdownlist:

        public string CountyValue
        {
            get { return txtCountyName.Text; }
            set { txtCountyName.Text = value; }
        }

Is there a better way to enumerate through this list of values and supply them to textbox.text? I have tried everything to fix this error.

EDIT
Also all my database columns are Varchars so there was no need to convert data types.

And I only get this error when I deploy my app via ClickOnce to clients PC.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:14:12+00:00Added an answer on May 30, 2026 at 11:14 pm

    From what I see, that Location is a single value, and there is no need to create a List. So that means you can avoid iterating over a list, and do this instead:

    var ObjectContext = new ObjectContext();
    
        var details = ObjectContext.TableLocation
                        .First(x => x.LocationName == LocationValue)
                        .Select(x => 
                                new { 
                                    PostalCode = x.postalCode,
                                    Phone1 = x.phoneNumber1,
                                    Phone2 = x.phoneNumber2,
                                    Supervisor = x.supervisor
                                });
    
    txtPostalCode.Text = details.PostalCode;
    txtPhone1.Text = details.Phone1;
    txtPhone2.Text = details.Phone2;
    txtSupervisor.Text = details.Supervisor;
    

    ADDED:
    Also check this MSDN Reference, according to it, there are several scenarios where ShowDialog() could throw an InvalidOperationException, that are unrelated to LINQ-to-SQL or EF.
    ADDED: From that MSDN article it says this:

    When a form is displayed as a modal dialog box, clicking the Close
    button (the button with an X at the upper-right corner of the form)
    causes the form to be hidden and the DialogResult property to be set
    to DialogResult.Cancel. Unlike non-modal forms, the Close method is
    not called by the .NET Framework when the user clicks the close form
    button of a dialog box or sets the value of the DialogResult property.
    Instead the form is hidden and can be shown again without creating a
    new instance of the dialog box. Because a form displayed as a dialog
    box is hidden instead of closed, you must call the Dispose method of
    the form when the form is no longer needed by your application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an ASP.NET form for data-entry. Users have to select a client from
I have a data entry form where user enters lots of data. When user
I have a pretty big data entry form which has many text fields ,
I have data entry form like... Data Entry Form http://img192.imageshack.us/img192/2478/inputform.jpg There are some empty
Folks, I have an MVC3 data entry form scenario that involves asking the user
I am working on app which have data entry form which have Some fields
I have some hierarchical data - each entry has an id and a (nullable)
I have a form that is used for data entry, and on one form
I have a custom data entry form which is bound to a ViewModel (VM).
I have a data entry form that has remote validation set up to check

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.