2009-04-25 5 views
0

ComboBoxはBindingSourceにバインドされていますが、これはLinqテーブルにバインドされています。ComboBoxとLinq to Sql for Winforms

また、ComboBoxはLinqテーブルであるデータソースから塗りつぶされます。

ユーザーがComboBoxでアイテムを選択するたびに、BindingSource.Currentのプロパティの1つに新しい値を割り当てたいとします。私はComboBoxのSelectionChangeCommittedイベントを使用する必要があることをMSDNから理解しました。ここで

は擬似コードです:

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 
} 

は私がmyCB.DataBindings [0] .WriteValue()を使用する必要があります。 ?それとも良い方法がありますか?

ありがとうございます。

答えて

0

私はこの方法に関係なく、オブジェクトはデータベースからオブジェクトをキャプチャした値で更新することができるでしょうコンボボックスなどに永続化する方法の

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(); 

ような何かをするだろう

ご連絡ください