operation is not valid due to the current state of the object

Posts   
 
    
yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 20-May-2006 16:07:20   

version 1.0.2005.1 final (self-servicing) VS2005 winforms


hiya,

I have a combobox that contains a databindings that links to a child entityCollection. The child EntityCollection is also bound to a datagridView.


 TblReturnProductConditionCollection returnProductConditionCollection = new TblReturnProductConditionCollection();
            returnProductConditionCollection.GetMulti(null);

            cboReturnProductCondition.DataSource = returnProductConditionCollection;
            cboReturnProductCondition.ValueMember = "returnProductCondtionId";
            cboReturnProductCondition.DisplayMember = "returnProductCondtionName";
            cboReturnProductCondition.DataBindings.Clear();
            cboReturnProductCondition.DataBindings.Add(new Binding("SelectedValue", this.childBindingSource, myProject.TblReturnProductsFieldIndex.ReturnProductCondtionId.ToString(), true));

My problem:

When I select a differnt item in the combobox, I get one of 2 errors:

1) operation is not valid due to the current state of the object 2) value of '3' is not valid for index start

Hmm, I've no idea.

Can anyone help?

many thanks,

yogi

sparmar2000 avatar
Posts: 341
Joined: 30-Nov-2003
# Posted on: 20-May-2006 19:22:01   

Please refer to Using Generated Code -> Self Service -> Data Binding and perticulerly "Design time support in VS.NET 2005" section in the referance manual to see if this applies to you.

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 20-May-2006 19:49:01   

hiya,

I read the help. I am doing the databinding at runtime, in code. The only design-time stuff I have are the blank bindingSources that I dragged onto my form.

I set all the values for these bindingSources in code.

This is my code..Is there maybe something else that i should be aware of?

Cheers,

yogi


//predicate code.
  IPredicateExpression filtReturnProductCondition = new PredicateExpression();
            filtReturnProductCondition.Add(PredicateFactory.CompareValue(TblReturnProductsFieldIndex.ReturnProductCondtionId, ComparisonOperator.Equal, (int)cboReturnProductCondition.SelectedValue)); //
            filtReturnProductCondition.Add(PredicateFactory.CompareValue(TblReturnProductsFieldIndex.ReturnId, ComparisonOperator.Equal, _selectedReturnId));

//databindingCode
            tblReturnProductsCollection1.GetMulti(filtReturnProductCondition);
            childBindingSource.DataSource = tblReturnProductsCollection1;
            dgvReturns.DataSource = childBindingSource;


TblReturnProductConditionCollection returnProductConditionCollection = new TblReturnProductConditionCollection();
            returnProductConditionCollection.GetMulti(null);

            cboReturnProductCondition.DataSource = returnProductConditionCollection;
            cboReturnProductCondition.ValueMember = "returnProductCondtionId";
            cboReturnProductCondition.DisplayMember = "returnProductCondtionName";
            cboReturnProductCondition.DataBindings.Clear();
            cboReturnProductCondition.DataBindings.Add(new Binding("SelectedValue", this.childBindingSource, myProject.TblReturnProductsFieldIndex.ReturnProductCondtionId.ToString(), true));

the cboReturnProductCondition_SelectIndexChanged event handler calls the above code.

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 20-May-2006 23:19:26   

hiya,

I'm still no further forward. Has anyone seen any of the errors that I am getting? The strange thing is that, I click "OK" to the error dialog box, then the operation actually succeeds confused

cheers,

yogi

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 21-May-2006 17:05:08   

right,

I think I know WHY i'm getting this error, but it's probably better if I start a new post.

cheers,

yogi