/// <summary> /// 移动表格分录,保证模型与视图索引匹配 /// </summary> /// <param name="view"></param> /// <param name="entityKey"></param> /// <param name="selRows"></param> /// <param name="iTargetPos"></param> /// <param name="isRelativePos"></param> /// <param name="callback"></param> public static void MoveEntryRow(this IDynamicFormView view, string entityKey, int[] selRows, int iTargetPos, bool isRelativePos = true, Action <int[], int, bool> callback = null) { if (selRows == null || selRows.Any() == false) { return; } var entryEntity = view.BillBusinessInfo.GetEntity(entityKey); DynamicObjectCollection dataEntities = view.Model.GetEntityDataObject(entryEntity); DynamicObject targetRowObj = null; if (!isRelativePos) { if (iTargetPos < 0 || iTargetPos >= dataEntities.Count) { return; } targetRowObj = view.Model.GetEntityDataObject(entryEntity, iTargetPos); if (targetRowObj == null) { return; } } var selRowObjItems = selRows.Select(o => view.Model.GetEntityDataObject(entryEntity, o)) .ToList(); List <int> lstNewSelRows = new List <int>(); for (int i = selRowObjItems.Count - 1; i >= 0; i--) { if (selRowObjItems[i] == null) { continue; } var selRowObj = selRowObjItems[i]; int iSrcRowIndex = view.Model.GetRowIndex(entryEntity, selRowObj); int iTargetRowIndex = iSrcRowIndex + iTargetPos; if (!isRelativePos) { iTargetRowIndex = view.Model.GetRowIndex(entryEntity, targetRowObj); } if (iTargetRowIndex > dataEntities.Count - 1 || iTargetRowIndex < 0) { continue; } dataEntities.Remove(selRowObj); dataEntities.Insert(iTargetRowIndex, selRowObj); lstNewSelRows.Add(iTargetRowIndex); } int iSeq = 1; foreach (var dataEntity in dataEntities) { if (entryEntity.SeqDynamicProperty != null) { entryEntity.SeqDynamicProperty.SetValue(dataEntity, iSeq++); } } if (callback != null) { callback(selRows, iTargetPos, isRelativePos); } view.UpdateView(entityKey); if (lstNewSelRows.IsEmpty()) { lstNewSelRows.AddRange(selRows); } if (lstNewSelRows.Any()) { EntryGrid grid = view.GetControl <EntryGrid>(entityKey); grid.SelectRows(lstNewSelRows.ToArray()); grid.SetFocusRowIndex(lstNewSelRows.Last()); } }