开发者

c# objectlistview model update not drawn

I'm using objectlistview (olv) to display sets of child attributes dependent on a master record. it's a c# app that uses linq. i do not use olv as a row editor; instead, i pop out the underlying child record into a dynamic, more-detailed, non-wpf dialog. if an olv's column's model aspect relies on objects (ie, foreign keys), the olv display does not refresh.

for example,

an olv display contains a log of statuses, and one column is "Status.Code" which relates to the object "Log" like this: "Log.Status". because it is linq, "Log.StatusId" also exists in the linq DataContext (but is not configured to display in the olv). "Log.StatusId" returns correctly from the edit dialog and "Log.Status" populates correctly immediately after edit dialog terminiates. also, linq saves edits correctly.

i've tried and failed with olv's Invalidate() and BuildList() and a few days' worth of hoodoo. this is an ordinary olv - not a rapidlistview or a datalistview. any perspective welcomed.

the code below underscores handling of foreign keys. for non-olv users, olv is configured like most other windows form controls.

...
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
             ...
         }
         ...
     }
     ...
 }
 ...


AddObjects instead of AddObject did not work. november 2008 fixes also did not remedy. my current, only solution is to clear and re-add an edited list of original objects with a hack value id value for additions. any datasource binding / state is irrelevant since records are disassociated linq objects. yay.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜