is the databinding getting confuse because of MULTIPLE potential matches?

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

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 (via a bindingSource) This bindingSource is also bound to a datagridView.

The combobox represents the "condition" that a product is in, eg, NEW or OLD


//Combobox is initially populated. (when winform is loaded)

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

//databindings are created whenever the "childBindingSource" changes
cboReturnProductCondition.DataBindings.Clear();
cboReturnProductCondition.DataBindings.Add(new Binding("SelectedValue", this.childBindingSource, myProject.TblReturnProductsFieldIndex.ReturnProductCondtionId.ToString(), true));

My problem:

Whenever is I select an option, If the filtered "childBindingSource" (which will poulate the datagridView) contains more than a SINGLE product with the SAME product condition, then I get the error:

<<operation is not valid, due to the current state of the object>>

I suspect that the databindings is becoming confused because there could be MULTIPLE products in the datasource that contain the same productConditionId

eg, the datagridView:

productId 1 productCondition NEW productId 2 productCondition NEW

I hope the above makes sense.

Please let me know if I should post more code / clarify.

I'm in a wee bit of a hurry with this one :-0 cheers,

yogi

sparmar2000 avatar
Posts: 341
Joined: 30-Nov-2003
# Posted on: 21-May-2006 18:45:24   

Seems to me somehow that the datagridview has a prblem with duplicate rows.

I am not hot on datagridview, but may be there is an configuration that is similer to 'allow duplicates' switch that you should be looking for. confused

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 21-May-2006 18:59:25   

hiya,

I don't think it's a datagridview issue, because they aren't duplicate rows..

productId 1 productCondition NEW productId 2 productCondition NEW

both productId and productCondition form the primary key.

Also, when I remove the follwing code, then I don't get the error:


cboReturnProductCondition.DataBindings.Add(new Binding("SelectedValue", this.childBindingSource, myProject.TblReturnProductsFieldIndex.ReturnProductCondtionId.ToString(), true));

make sense?

cheers,

yogi

sparmar2000 avatar
Posts: 341
Joined: 30-Nov-2003
# Posted on: 21-May-2006 21:30:23   

Yes it does make sense

Can you please try something. Instead of

cboReturnProductCondition.DataBindings.Add(new Binding("SelectedValue", this.childBindingSource, myProject.TblReturnProductsFieldIndex.ReturnProductCondtionId.ToString(), true));

that is cause error, is it possible for you to manually 'add' the rows (if it is possible to add rows manually to datagridviews).

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 22-May-2006 21:08:17   

Suspect it may be getting confused because the DGV is using Complex data binding and the combobox is using Simple.

The entity collection containing the data can have multplie child bindingsource objects.

I would suggest creating a second child bindingsource for the combobox that uses the same datasource as the first child bindingsource.

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

hiya,

I still cant get this. The combobox was previously databound as follows:


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

cboReturnProductCondition.DataBindings.Clear();
cboReturnProductCondition.DataBindings.Add(new Binding("SelectedValue", this.childBindingSource, myProject.TblReturnProductsFieldIndex.ReturnProductCondtionId.ToString(), true));

The entity collection containing the data can have multplie child bindingsource objects.

I would suggest creating a second child bindingsource for the combobox that uses the same datasource as the first child bindingsource.

Ok, I have changed the databindings to the following:


cboReturnProductCondition.DataBindings.Clear(); //SAME AS BEFORE
cboReturnProductCondition.DataBindings.Add(new Binding("SelectedValue", this.childBindingSource, myProject.TblReturnProductsFieldIndex.ReturnProductCondtionId.ToString(), true)); //SAME AS BEFORE
            
childBindingSourceProdCondition.DataSource = tblReturnProductsCollection1; //SAME DATASOURCE AS THE ONE THAT IS BOUND TO THE DGV BINDINGSOURCE
cboReturnProductCondition.DataSource = childBindingSourceProdCondition;     

Now, when I run my app again, I get an "object reference not set to an instance of the object"

..at this line:

 filtReturnProductCondition.Add(PredicateFactory.CompareValue(TblReturnProductsFieldIndex.ReturnProductCondtionId, ComparisonOperator.Equal, (int)cboReturnProductCondition.SelectedValue)); 

hmm, can anyone help?

cheers,

yogi

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 25-May-2006 00:27:35   

hiya folks,

I am trying my best to get to the bottom of this, but I can't reallly go any further.

Can anyone comment?

many thanks,

yogi

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 25-May-2006 10:22:40   

When you set a breakpoint on this line: filtReturnProductCondition.Add(PredicateFactory.CompareValue(TblReturnProductsFieldIndex.ReturnProductCondtionId, ComparisonOperator.Equal, (int)cboReturnProductCondition.SelectedValue));

which parameter / variable is null ?

Also keep in mind that with these complex databinding scenario's, it's often difficult for the reader to imagine what you're seeing simple_smile

Frans Bouma | Lead developer LLBLGen Pro
yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 25-May-2006 21:20:28   

hiya Frans,

The cboReturnProductCondition.SelectedValue)); is casuing the problem:

<error> (int)cboReturnProductCondition.SelectedValue Cannot unbox '((System.Windows.Forms.ListControl)(this.cboReturnProductCondition)).SelectedValue' as a 'int' int </error>

So, this is the show stopper for the moment.It somehow doesn't recognise the selectedValue of the combobox.

Any ideas?

Also keep in mind that with these complex databinding scenario's, it's often difficult for the reader to imagine what you're seeing

Agreed, in fact I'm amazed at how people are able to diagnose problems, simply from a well meaning but often unintentionally partial explanation.

keep up the good work wink

yogi

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 26-May-2006 11:28:09   

hiya,

Right, I think that the most likely explanation is that the bindingSource combination that I have for the combobox does not produce any values for the combobox.

therfore, the combobox only contains null, and the slected.value error occurs.

So, What is wrong with my databindings?

I have experimented with the "order" in which I assign the databindings..The same error occurs.

Maybe somoene could suggest some possible causes?

many thanks,

yogi

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 26-May-2006 17:43:09   

The error you get wth the unboxing of SelectedValue, it means that the selectedvalue isn't an int, but something else. Could you try in the debugger (with a breakpoint) to see what's in selectedvalue, at line: filtReturnProductCondition.Add(PredicateFactory.CompareValue(TblReturnProductsFieldIndex.ReturnProductCondtionId, ComparisonOperator.Equal, (int)cboReturnProductCondition.SelectedValue));

You cast it to an int, but if SelectedValue is a string, it will crash. (although I wonder why you didn't get a specified cast not valid error, but I guess that's because int is a valuetype)

Frans Bouma | Lead developer LLBLGen Pro
yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 26-May-2006 23:05:47   

hiya,

Ok, the combobox doesn't contain any values..

This is because it hasn't yet been databound.

The problem is that I was originally binding the combobox directly to an entityCollection.

However, I was getting the error that appears in the title, so I was advised to change it to complex databinding..hence the code below.

I can explain fully, but it's hard for me to know how well I've exaplined it thus far.

Can anyone help?

cheers,

yogi


tblReturnCollection1.GetMulti(null); 
parentBindingSource.DataSource = tblReturnCollection1;
            
IPredicateExpression filtReturnProductCondition = new PredicateExpression();

filtReturnProductCondition.Add(PredicateFactory.CompareValue(TblReturnProductsFieldIndex.ReturnProductCondtionId, ComparisonOperator.Equal, (int)cboReturnProductCondition.SelectedValue)); //SO, how do i get this to work..it has not yet been databound but how do I databind it if I want it to behave in the way I outlined earlier in this thread?
cboReturnProductCondition.SelectedValue)); 
            

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

cboReturnProductCondition.DataBindings.Clear();
cboReturnProductCondition.DataBindings.Add(new Binding("SelectedValue", this.childBindingSource, myProject.TblReturnProductsFieldIndex.ReturnProductCondtionId.ToString(), true));
childBindingSourceProdCondition.DataSource = tblReturnProductsCollection1;
cboReturnProductCondition.DataSource = childBindingSourceProdCondition; // THIS DATABIND DOESN'T PRODUCE ANY VALUES IN THE COMBOBOX ..
HOW WOULD THE COMBOBOX KNOW THAT IT NEEDS TO ONLY BIND TO SPECIFIC FIELDS IN THE ENTITY COLLECTION?     

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 27-May-2006 21:20:28   

Hiya,

Ok, I just realised that I had to add a field mapped on a related field.

I think that this was so that the combobox had both a:

1) displaymember 2) valueMember

The issue hasn't been totally resolved, but I'm nearer the end.

I'd like to close this thread and create a smaller thread.

thanks all,

yogi

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 29-May-2006 10:45:27   

Ok, I'll close the thread and you should start a new thread with new info. simple_smile If possible, try to post small screenshots of your databinding setup in vs.net, if that makes things more clear. I'm sorry it takes us so long to get a solution for you, though it's hard to get to the real problem in these situations as there are so many different details involved.

Frans Bouma | Lead developer LLBLGen Pro