/// <summary> /// 中指定对象(所在的行) /// exclusive 用于指定是否是排它性选择,既取消现有选择 /// </summary> /// <param name="obj"></param> /// <param name="exclusive"></param> public void Select(object obj, bool exclusive) { Debug.Assert(obj != null, "obj 为 null"); if (_currentCodon == null) { return; } IBindingListEx bindingList = GetBindingList(_currentCodon); if (bindingList == null || bindingList.Count == 0) { return; } if (exclusive) { ClearSelectedRows(); } if (obj == null) { return; } int index = bindingList.IndexOf(obj); if (index < 0) { return; } _dataGridView.Rows[index].Selected = true; }
public void Update(object obj) { Debug.Assert(obj != null, "obj为null"); if (obj == null) { return; } if (_currentCodon == null) { return; } IBindingListEx bindingList = GetBindingList(_currentCodon); if (bindingList == null) { return; } //Debug.Assert(bindingList.Contains(obj), "_bindingList中没有指定对象"); if (bindingList.Contains(obj) == false) { return; } if (_currentCodon.Compatible(obj)) { bindingList.ResetItem(bindingList.IndexOf(obj)); } }
/// <summary> /// 把目标对象移动到另一个对象之后 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sourceFilter"></param> /// <param name="targetFilter"></param> public void MoveAfter <T>(Filter <T> sourceFilter, Filter <T> targetFilter) where T : class { object sourceObj, targetObj; GetMoveObject <T>(sourceFilter, targetFilter, out sourceObj, out targetObj); //Debug.Assert(sourceObj != null && targetObj != null, "指定的对象为null"); if (sourceObj == null && targetObj == null) { return; } Debug.Assert(sourceObj != targetObj, "指定的两个对象是同一个对象"); if (sourceObj == targetObj) { return; } if (_currentCodon == null) { return; } IBindingListEx bindingList = GetBindingList(_currentCodon); int sourceIndex = bindingList.IndexOf(sourceObj); int targetIndex = bindingList.IndexOf(targetObj); //如果targetObj刚好在beforeObj之后,就无需移动了 if (sourceIndex - targetIndex == 1) { return; } bindingList.Remove(sourceObj); //要重新 IndexOf(beforeObj) ,因为targetObj被remove之后,beforeObj的下标就可能被改变了 bindingList.Insert(bindingList.IndexOf(targetObj) + 1, sourceObj); }