2012-08-07 32 views
0

如果我想一起使用gridView.EndDataUpdate (gridView.BeginDataUpdate)gridView.EndSummaryUpdate (gridView.BeginSummaryUpdate),哪一個應該是正確的順序?
訂購1:是否有命令調用gridView.EndDataUpdate,gridView.EndUpdate,gridView.EndSummaryUpdate?

gridView.BeginDataUpdate(); 
gridView.BeginSummaryUpdate(); 
... 
gridView.EndSummaryUpdate(); 
gridView.EndDataUpdate(); 

訂購2:

gridView.BeginDataUpdate(); 
gridView.BeginSummaryUpdate(); 
... 
gridView.EndDataUpdate(); 
gridView.EndSummaryUpdate(); 

當我應該使用gridView.EndUpdate (gridView.BeginUpdate),有沒有順序要求?

謝謝!

回答

1

BaseView.BeginUpdate/BaseView.EndUpdate方法鎖定視圖並阻止後續的視覺更新。通過使用BeginUpdate和EndUpdate方法無法避免任何數據更新。相反,必須使用BaseView.BeginDataUpdateBaseView.EndDataUpdate方法。每當彙總項目添加到網格視圖或修改其設置時,網格會自動重新計算彙總。要在所有彙總項目正確初始化之前防止彙總計算,請使用BeginSummaryUpdateEndSummaryUpdate方法。
這裏是所有這些方法使用的詳細說明:
- Batch Modifications Overview

在你的情況,你可以附上數據和彙總更新與視覺更新內容如下:

view.BeginUpdate(); 
try { 
    ...view options modifications... 

    view.BeginDataUpdate(); 
    try { 
     ...data modifications... 
    } 
    finally{ view.EndDataUpdate(); } // real data update here 

    view.BeginSummaryUpdate(); 
    try { 
     ...summary modifications... 
    } 
    finally{ view.EndSummaryUpdate(); } // real summary recalculation 

    ...another view options modifications... 
} 
finally{ view.EndUpdate(); } // real visual update