2010-02-05 85 views
2

我正在撕掉我的頭髮,因爲這個驚人的問題。DevExpress LookUpEdit行爲

我從代碼綁定2 LookUpEdit:

  MyBinding.DataSource = typeof(MyObject); 
     MyBinding.DataSource = _dataObject.GetMyList(); 

     firstLookUp.DataBindings.Add("EditValue", MyBinding, "Code"); 
     firstLookUp.Properties.DataSource = MyBinding; 
     firstLookUp.Properties.ValueMember = "Code"; 
     firstLookUp.Properties.DisplayMember = "Code"; 

     secondLookUp.DataBindings.Add("EditValue", MyBinding, "Info"); 
     secondLookUp.Properties.DataSource = MyBinding; 
     secondLookUp.Properties.ValueMember = "Info"; 
     secondLookUp.Properties.DisplayMember = "Info"; 

第一個問題是:改變對兩個查找未反映不斷變化的另一個之一的價值!但即時通訊使用相同的BindingSource,是不是位置相同?

另一個是:他們都自動填充列,我不想顯示所有列,試圖刪除,未找到異常列,如果我添加,我得到重複列! 我不明白!

回答

1

更改LookupEdit的EditValue不直接綁定到BindingSource.Current位置。

你如果要同時LookupEdits鏈接你可能會更好時,另一種是改變設定一個的編輯值使用類似

lookUpEdit1.Properties.GetDataSourceRowByKeyValue(lookUpEdit1.EditValue) 

其次,你應該能夠清除列的列表,像這樣:

lookUpEdit1.Properties.Columns.Clear(); 
lookUpEdit1.Properties.Columns.Add(new LookUpColumnInfo("FirstName")); 
+0

所以一切都在代碼人工事件發生。 Thanx回覆。 – 2010-02-23 11:09:18

+0

那麼,列應該只是你指定的列,Clear()只在那裏,因爲你說你得到了兩倍。通常情況下,我看到的行爲是顯示所有列,如果您在設置時指定了none,並且只指定了指定的列。 – csjohnst 2010-02-23 13:33:42

1

正如這裏說

http://www.devexpress.com/Support/Center/p/B138420.aspx

http://www.devexpress.com/Support/Center/p/A2275.aspx

LookupEdit不更新的當前屬性BindingSource的。

我們使用下面的代碼作爲一種解決方法:

/// <summary> 
/// Wrapper around DevExpress.XtraEditors.LookUpEdit to fix bug with adjusting the BindingSources Current Position 
/// </summary> 
public sealed class LookUpEditWithDataSource : LookUpEdit 
{ 
    private bool firstCall = true; 

    /// <summary> 
    /// Called when the edit value changes. 
    /// </summary> 
    protected override void OnEditValueChanged() 
    { 
     base.OnEditValueChanged(); 

     if (this.Properties.DataSource == null) 
     { 
      return; 
     } 

     if (this.BindingContext == null) 
     { 
      return; 
     } 

     if (this.firstCall) 
     { 
      this.firstCall = false; 

      // HACK 
      // starting and selecting the first item 
      // doesn't work so we change the position to the first item 
      this.BindingContext[this.Properties.DataSource].Position = 1; 
     } 

     this.BindingContext[this.Properties.DataSource].Position = this.Properties.GetDataSourceRowIndex(this.Properties.ValueMember, this.EditValue); 
    } 
} 
+0

謝謝你的觀點。 – 2010-09-02 13:50:07