2011-03-16 47 views
0

我使用objectlistview(olv)顯示取決於主記錄的子屬性集。它是一個使用linq的c#應用程序。我不使用olv作爲行編輯器;相反,我彈出底層的子記錄到一個動態的,更詳細的,非wpf對話框。如果olv的列模型方面依賴於對象(即外鍵),則olv顯示不刷新。c#objectlistview model udpate not drawn

例如,

一個OLV顯示包含日誌狀態的,和一列是「Status.Code」,其涉及到對象「日誌」這樣的:「Log.Status」。因爲它是linq,「Log.StatusId」也存在於linq DataContext中(但未配置爲在olv中顯示)。在編輯對話框中正確返回「Log.StatusId」,編輯對話框終止後立即正確填充「Log.Status」。此外,linq保存正確的編輯。

我試過了,並且失敗了,使用了olv的Invalidate()和BuildList()以及幾天的不良經驗。這是一個普通的olv - 不是快速列表視圖或數據視圖。歡迎任何觀點。

下面的代碼強調外鍵的處理。對於非olv用戶,olv的配置與大多數其他窗體控件一樣。

... 
object old = DataService.Clone<object>(olv.SelectedObject); 
    // where old ~ reference base for changes to olv object - for state management and linq 
object row = olv.SelectedObject; 
    // where row ~ object that receives edits and undergoes updates via linq 
Dictionary<string, object> rowState = new Dictionary<string, object>(); 
    // where ~ rowState<fieldName,originalValue> 
RecordDetail dlg = new RecordDetail(GetUser(), master.GetType(), row, rowState); 
    // where ~ GetUser() & master.GetType() configure form RecordDetail 
DialogResult dr = dlg.ShowDialog(); 
if (dr == DialogResult.OK) 
{ 
    if (row != null && rowState != null && rowState.Count > 0) 
    { 
     int id = DataService.GetPrimaryKeyValue(row); 
     if (id > 0) /// if not new 
     { 
      int pk = DataService.GetPrimaryKeyValue(old); 
      MultiState state = getChildState(olv); // olv.Tag contains state 
      foreach (KeyValuePair<string, object> change in rowState) 
      { 
       MethodInfo mi = old.GetType().GetMethod(DataService.LINQ_GET + change.Key); 
       object newValue = mi.Invoke(row, null); 
       bool ok = DataService.ManageMultiStateUpdate(ref state, pk, change.Key, newValue, change.Value, old); 
       /// INFO populate fk objects for olv // <== works ok 
       Type tdomain = DataService.GetForeignKeyTypeAsAliasSafe(old.GetType(), change.Key); 
       if (tdomain != null) 
       { 
        object fko = GetForeignKey(tdomain, change.Value); 
        mi = row.GetType().GetMethod(DataService.LINQ_SET + change.Key.Replace(DataService.LI_ID, "")); 
        object[] args = { fko }; 
        mi.Invoke(row, args); 
       } 
       ... 
      } 
      olv.BuildList(); // <== both this and olv.Invalidate() fail to display foreign key updates 
      ... 
     } 
     ... 
    } 
    ... 
} 
... 

回答

0

AddObjects instead of AddObject沒有工作。 november 2008 fixes也沒有補救措施。我目前唯一的解決方案是清除並重新添加一個編輯的原始對象列表,並添加一個黑客值id值。任何數據源綁定/狀態都是不相關的,因爲記錄是分離的linq對象。好極了。