views:

430

answers:

1

Edit: More than a day. Still no answer! Is question not clear?

I have ComboBox bound to BindingSource which in turn is bound to Linq Table.

Also, ComboBox is filled from datasource which is a Linq Table.

I want to assign new value to one of properties of BindingSource.Current whenever user selects item in ComboBox. I understood from MSDN that I need to use SelectionChangeCommitted event of ComboBox.

Here is pseudo code:

myCB_SelectionChangeCommitted(...)
{
    var val = myCB.SelectedValue; //I get selected value from user.
    var q = bindingSource.Current as XYZ;
    //Ommitted validation code to check if q is okay to work with
    q.SomeProperty = NewCalculatedValue; //SomeProperty is bound to label
    //After above line, myCB.SelectedValue is lost!
    //It seems that this event fires **before** selected value 
        //is written to bound data source
}

Q: Do I have to use myCB.DataBindings[0].WriteValue(); ? Or is there a better way?

Thanks in advance.

A: 

I would do something like

long index = q.databaseindex;
LinqObject = (from l in DataContext.linqtable where l.index = index select l).First();
   //Make sure you do a check that count > 0 before calling First!
LinqObject.property = value;
LinqObject.SubmitChanges();

This way regardless of how the object is persisted to the ComboBox you'll be able to capture the object from the database and then update it with the value, etc.

Let us know

DNeoMatrix