Question

 foreach (Listing s in fx)
            {
                ListingBindingSource.Add(s);
            }

This in my code causes the following error:

Invalid operation error: Operation is not valid due to the current state of the object.

Now i checked, I am running this on the main thread.

Also, it was working before. What changed recently is i changed Listing members, two of them, from int to string. I thought if i delete Listbindingsource and remake it, it would automatically change that. But it seems i have to do something else. Can anyone shed some light here. ListBindsource is the datasource to a datagridview. thanks

***SOLUTION******

 public Form1()
        {
            InitializeComponent();  Listing s1 = new  Listing();
             ListingBindingSource.Add(s1);
}

for some reason this added it. When the form was created for some reason null was being passed into the bindingsource. why, i don't know.

Some additional info:

If i remove the bindingsource as a datasource of the gridview, the error vanishes

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top