回复 寒枫天伤 - PSP 的问题

      今天收到“寒枫天伤 - PSP”的问题(老大,名字能不能简单点,好难打也),询问载体设计的问题,乱谈一下吧,不好你当胡扯蛋了。

载体的设计有俩个思路,一个是表格式的,一个是层次的。

      ms的ADO、DataSet就是表格式的,采用行、列组成的表,然后表集合之间建立联系。他更贴近关系型数据库的结构,因此使用简单、可以充分利用已经成熟的大量研究成果。缺点就是他是抽象的,不直观。

      通常的xml和O/R的设计就是层次的,局部来说也是行(集合)、列(属性)组成表(对象),区别是表(对象)之间不是平等的关系,而是建立了有点像树一样的结构。好处吗,编写代码的时候看着舒服些罗(不是我打击你),缺点吗,一沓子了,我最头大的是数据跟踪问题。

      我无法在一片文章中说明所有的事情,例如序列化、继承原则、CRUD、数据跟踪一大堆要处理的事情。

      先说说 IBindList和ICancelAddNew接口吧,IBindList是列表绑定的基础接口,他继承于IList接口,如果你想绑定到某个表格或者列表中,IList基本上够了(实际上数组和ICollection也可以),但IBindList提供是否能新增、编辑和删除的选项,还提供排序、查找等功能(我可没有实现这个复杂的功能,我使用表格本身的功能),最重要的是他提供了ListChanged事件,这个是你通知外界你的集合发生改变的最好途径,所以你的集合最好是实现IBindList,而不紧紧是IList。

      ICancelAddNew接口用在表格的编辑中,你使用表格的时候都知道你新建一行的时候可以按ESC键取消新建,实际内部的工作原理是:已经新建了行并添加到行集合,当你按ESC时,删除掉刚才的一行,所以你必须记住刚才新建的行是第多少行。

(如果没有记错的话,.net 1.1是没有这个接口的 ,.net 2.0才有)

      下面的代码是部分的集合代码(不能运行的),不要以为我能写多好的程序,其实我是抄System.ComponentModel.Collections.Generic.BindingList<T>的。

None.gif
ContractedBlock.gifExpandedBlockStart.gif
Using directives #region Using directives
InBlock.gif
using System;
InBlock.gif
using System.Collections;
InBlock.gif
using System.ComponentModel;
InBlock.gif
using Mango.Common.Data;
InBlock.gif
using Mango.Common.Properties;
InBlock.gif
using System.Reflection;
ExpandedBlockEnd.gif
#endregion

None.gif
None.gif
namespace  Mango.Common.Data
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary> 行集合对象的基础类 </summary>
InBlock.gif    public class DataRowCollectionBase : CollectionBase, IBindingList, IList, ICollection, IEnumerable, ICancelAddNew
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
// Fields
InBlock.gif
        private int addNewPos;
InBlock.gif        
private bool hookingItems;
InBlock.gif        
private PropertyChangedEventHandler onItemPropertyChanged;
InBlock.gif        
private bool allowNew;
InBlock.gif        
private bool allowEdit;
InBlock.gif        
private bool allowRemove;
InBlock.gif
InBlock.gif        
private Type _itemType;
InBlock.gif        
private object _parent;
InBlock.gif
InBlock.gif        
// Events
InBlock.gif
        public event AddingNewEventHandler AddingNew;
InBlock.gif        
public event ListChangedEventHandler ListChanged;
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
类的初始化方法#region 类的初始化方法
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 创建无父对象的集合 </summary>
InBlock.gif        public DataRowCollectionBase()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.addNewPos = -1;
InBlock.gif            
this.allowNew = true;
InBlock.gif            
this.allowEdit = true;
InBlock.gif            
this.allowRemove = true;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 创建集合,并为集合设置父对象 </summary>
InBlock.gif        public DataRowCollectionBase(object parent) :this()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            _parent 
= parent;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
AddNew相关方法#region AddNew相关方法
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 获取集合类的名细类型
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        protected virtual Type GetCollectionItemType()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (_itemType == null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Type collType 
= this.GetType();
InBlock.gif                
object[] ps = collType.GetCustomAttributes(typeof(DbCollectionAttribute), true);
InBlock.gif                
if (ps == null || ps.Length == 0)
InBlock.gif                    
throw new ApplicationException(string.Format(Resources.Error_NotSetDbCollAtt, collType.Name));
InBlock.gif                _itemType 
= ((DbCollectionAttribute)ps[0]).TypeContainedInCollection;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
return _itemType;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 引发 AddingNew 事件 </summary>
InBlock.gif        protected virtual void OnAddingNew(AddingNewEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (this.AddingNew != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.AddingNew(this, e);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 返回新的对象 </summary>
InBlock.gif        private object FireAddingNew()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            AddingNewEventArgs addNewArgs 
= new AddingNewEventArgs(null);
InBlock.gif            
this.OnAddingNew(addNewArgs);
InBlock.gif            
return addNewArgs.NewObject;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 在向 DataRowCollectionBase 实例中插入新元素之前执行其他自定义进程。 </summary>
InBlock.gif        protected override void OnInsert(int index, object value)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//检查新对象的父对象
InBlock.gif
            DataRowBase row = value as DataRowBase;
InBlock.gif            
if (row != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (row.Parent != null)
InBlock.gif                    
throw new ArgumentException(Resources.Error_ColHaveParent);
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
this.EndNew(this.addNewPos);
InBlock.gif            
this.HookItem(value, true);
InBlock.gif
InBlock.gif            
base.OnInsert(index, value);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 在向 DataRowCollectionBase 实例中插入新元素之后执行其他自定义进程。 </summary>
InBlock.gif        protected override void OnInsertComplete(int index, object value)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//设置新对象的父对象
InBlock.gif
            DataRowBase row = value as DataRowBase;
InBlock.gif            
if (row != null)
InBlock.gif                row.SetParent(_parent);
InBlock.gif
InBlock.gif            
base.OnInsertComplete(index, value);
InBlock.gif            
this.FireListChanged(ListChangedType.ItemAdded, index);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 将新项添加到列表。</summary>
InBlock.gif        object IBindingList.AddNew()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
object newObject = this.AddNewCore();
InBlock.gif            
this.addNewPos = (newObject != null? base.List.IndexOf(newObject) : -1;
InBlock.gif            
return newObject;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 将新项添加到列表。 </summary>
InBlock.gif        protected virtual object AddNewCore()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
object newObject = this.FireAddingNew();
InBlock.gif            
if (newObject == null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                newObject 
= Activator.CreateInstance(GetCollectionItemType());
InBlock.gif                
//自动填充关键字
InBlock.gif
                IDataRow dataRow = newObject as IDataRow;
InBlock.gif                
if (dataRow != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    DataRowType t 
= dataRow.GetDataRowType();
InBlock.gif                    PropertyInfo pi 
= t.GetPrimaryKeyProperty();
InBlock.gif                    pi.SetValue(dataRow, Guid.NewGuid().ToString(
"N"), null);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
base.List.Add(newObject);
InBlock.gif            
return newObject;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
ListChanged事件的支持#region ListChanged事件的支持
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 引发 ListChanged 事件 </summary>
InBlock.gif        protected virtual void OnListChanged(ListChangedEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (this.ListChanged != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.ListChanged(this, e);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//内部引发ListChanged事件
InBlock.gif
        private void FireListChanged(ListChangedType listChangedType, int index)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.OnListChanged(new ListChangedEventArgs(listChangedType, index));
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//内部引发ListChanged事件
InBlock.gif
        private void FireListChanged(ListChangedType listChangedType, int index,string propertyName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            PropertyDescriptor propDesc 
= TypeDescriptor.CreateProperty(GetCollectionItemType(), propertyName,typeof(string), null);
InBlock.gif            
this.OnListChanged(new ListChangedEventArgs(listChangedType, index,propDesc));
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 返回/设置是否引发ListChanged中ItemChanged项目 </summary>
InBlock.gif        public bool RaiseItemChangedEvents
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this.hookingItems;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (this.hookingItems != value)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.HookItems(false);
InBlock.gif                    
this.hookingItems = value;
InBlock.gif                    
this.HookItems(true);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 引发重新更新事件 </summary>
InBlock.gif        public void ResetBindings()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.FireListChanged(ListChangedType.Reset, -1);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 引发某个元素的改动事件 </summary>
InBlock.gif        public void ResetItem(int position)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.FireListChanged(ListChangedType.ItemChanged, position);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//拦截/取消元素
InBlock.gif
        private void HookItem(object item, bool hook)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (!this.hookingItems)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if (this.onItemPropertyChanged == null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.onItemPropertyChanged = new PropertyChangedEventHandler(this.OnItemPropertyChanged);
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            IPropertyChange tmp 
= item as IPropertyChange;
InBlock.gif            
if (tmp != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (hook)
InBlock.gif                    tmp.PropertyChanged 
+= this.onItemPropertyChanged;
InBlock.gif                
else
InBlock.gif                    tmp.PropertyChanged 
-= this.onItemPropertyChanged;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//拦截/取消指定索引的元素
InBlock.gif
        private void HookItemAt(int index, bool hook)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if ((this.hookingItems && (index >= 0)) && (index < base.Count))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.HookItem(base.List[index], hook);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//拦截/取消所有元素
InBlock.gif
        private void HookItems(bool hook)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (!this.hookingItems)
InBlock.gif                
return;
InBlock.gif
InBlock.gif            IEnumerator e 
= base.GetEnumerator();
InBlock.gif            
while (e.MoveNext())
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
object tmp = e.Current;
InBlock.gif                
this.HookItem(tmp, hook);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//在元素发生改变时调用
InBlock.gif
        private void OnItemPropertyChanged(object sender, PropertyChangedEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.FireListChanged(ListChangedType.ItemChanged, base.List.IndexOf(sender), e.PropertyName);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
Clear相关方法#region Clear相关方法
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 在清除 DataRowCollectionBase 中所有实例之前执行其他自定义进程。</summary>
InBlock.gif        protected override void OnClear()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.EndNew(this.addNewPos);
InBlock.gif            
this.HookItems(false);
InBlock.gif
InBlock.gif            
//删除父对象关联,注意:这里不能会滚操作
InBlock.gif
            DataRowBase row;
InBlock.gif            
foreach (object item in InnerList)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                row 
= item as DataRowBase;
InBlock.gif                
if (row != null)
InBlock.gif                    row.SetParent(
null);
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
base.OnClear();
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 在清除 DataRowCollectionBase 中所有实例之后执行其他自定义进程。 </summary>
InBlock.gif        protected override void OnClearComplete()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
base.OnClearComplete();
InBlock.gif            
this.FireListChanged(ListChangedType.Reset, -1);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
Remove相关方法#region Remove相关方法
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 在向 DataRowCollectionBase 实例中移出元素之前执行其他自定义进程。 </summary>
InBlock.gif        protected override void OnRemove(int index, object value)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.EndNew(this.addNewPos);
InBlock.gif            
this.HookItemAt(index, false);
InBlock.gif            
base.OnRemove(index, value);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 在向 DataRowCollectionBase 实例中移出元素之后执行其他自定义进程。 </summary>
InBlock.gif        protected override void OnRemoveComplete(int index, object value)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//删除父对象关联
InBlock.gif
            DataRowBase row = value as DataRowBase;
InBlock.gif            
if (row != null)
InBlock.gif                row.SetParent(
null);
InBlock.gif
InBlock.gif            
base.OnRemoveComplete(index, value);
InBlock.gif            
this.FireListChanged(ListChangedType.ItemDeleted, index);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
Set相关方法#region Set相关方法
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 当在 DataRowCollectionBase 实例中设置值后执行其他自定义进程。</summary>
InBlock.gif        protected override void OnSetComplete(int index, object oldValue, object newValue)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//删除旧对象的父对象
InBlock.gif
            DataRowBase oldRow = oldValue as DataRowBase;
InBlock.gif            
if (oldRow != null)
InBlock.gif                oldRow.SetParent(
null);
InBlock.gif
InBlock.gif            
//设置新对象的父对象
InBlock.gif
            DataRowBase newRow = newValue as DataRowBase;
InBlock.gif            
if (newRow != null)
InBlock.gif                newRow.SetParent(_parent);
InBlock.gif
InBlock.gif            
base.OnSetComplete(index, oldValue, newValue);
InBlock.gif            
this.FireListChanged(ListChangedType.ItemChanged, index);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
ICancelAddNew支持#region ICancelAddNew支持
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 取消新建的行 </summary>
InBlock.gif        public void CancelNew(int itemIndex)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if ((this.addNewPos >= 0&& (this.addNewPos == itemIndex))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.RemoveAt(this.addNewPos);
InBlock.gif                
this.addNewPos = -1;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 结束新建行的编辑 </summary>
InBlock.gif        public void EndNew(int itemIndex)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if ((this.addNewPos >= 0&& (this.addNewPos == itemIndex))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.addNewPos = -1;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
集合是否可以改动的支持#region 集合是否可以改动的支持
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 获取/设置是否可以使用 AddNew 向列表中添加项。 </summary>
InBlock.gif        public bool AllowNew
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return ((IBindingList)this).AllowNew;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.allowNew = value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 获取是否可以使用 AddNew 向列表中添加项。 </summary>
InBlock.gif        bool IBindingList.AllowNew
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this.AllowNewCore;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 获取是否可以使用 AddNew 向列表中添加项。 </summary>
InBlock.gif        protected virtual bool AllowNewCore
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this.allowNew;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 获取/设置是否可更新列表中的项。 </summary>
InBlock.gif        public bool AllowEdit
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return ((IBindingList)this).AllowEdit;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.allowEdit = value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 获取是否可更新列表中的项。</summary>
InBlock.gif        bool IBindingList.AllowEdit
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this.AllowEditCore;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 获取是否可更新列表中的项。 </summary>
InBlock.gif        protected virtual bool AllowEditCore
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this.allowEdit;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 获取/设置是否可以使用 Remove 或 RemoveAt 从列表中移除项。 </summary>
InBlock.gif        public bool AllowRemove
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return ((IBindingList)this).AllowRemove;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.allowRemove = value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 获取是否可以使用 Remove 或 RemoveAt 从列表中移除项。 </summary>
InBlock.gif        bool IBindingList.AllowRemove
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this.AllowRemoveCore;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 获取是否可以使用 Remove 或 RemoveAt 从列表中移除项。 </summary>
InBlock.gif        protected virtual bool AllowRemoveCore
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this.allowRemove;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
排序和查询功能的支持#region 排序和查询功能的支持
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 获取当列表更改或列表中的项更改时是否引发 ListChanged 事件。 </summary>
InBlock.gif        public bool SupportsChangeNotification
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this.SupportsChangeNotificationCore;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 获取当列表更改或列表中的项更改时是否引发 ListChanged 事件。 </summary>
InBlock.gif        protected virtual bool SupportsChangeNotificationCore
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return true;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 获取列表是否支持使用 Find 方法进行搜索。 </summary>
InBlock.gif        public bool SupportsSearching
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this.SupportsSearchingCore;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 获取列表是否支持使用 Find 方法进行搜索。 </summary>
InBlock.gif        protected virtual bool SupportsSearchingCore
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return false;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 获取列表是否支持排序 </summary>
InBlock.gif        public bool SupportsSorting
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this.SupportsSortingCore;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 获取列表是否支持排序 </summary>
InBlock.gif        protected virtual bool SupportsSortingCore
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return false;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 获取是否对列表中的项进行排序。</summary>
InBlock.gif        public bool IsSorted
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this.IsSortedCore;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 获取是否对列表中的项进行排序。 </summary>
InBlock.gif        protected virtual bool IsSortedCore
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return false;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 获取正在用于排序的 PropertyDescriptor。 </summary>
InBlock.gif        public PropertyDescriptor SortProperty
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this.SortPropertyCore;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 获取正在用于排序的 PropertyDescriptor。 </summary>
InBlock.gif        protected virtual PropertyDescriptor SortPropertyCore
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return null;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 获取排序的方向。 </summary>
InBlock.gif        public ListSortDirection SortDirection
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this.SortDirectionCore;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 获取排序的方向。</summary>
InBlock.gif        protected virtual ListSortDirection SortDirectionCore
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return ListSortDirection.Ascending;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 根据 PropertyDescriptor 和 ListSortDirection 对列表进行排序。 </summary>
InBlock.gif        public void ApplySort(PropertyDescriptor property, ListSortDirection direction)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.ApplySortCore(property, direction);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 根据 PropertyDescriptor 和 ListSortDirection 对列表进行排序。 </summary>
InBlock.gif        protected virtual void ApplySortCore(PropertyDescriptor property, ListSortDirection direction)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
throw new NotSupportedException();
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 使用 ApplySort 移除任何已应用的排序。 </summary>
InBlock.gif        public void RemoveSort()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.RemoveSortCore();
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 使用 ApplySort 移除任何已应用的排序。</summary>
InBlock.gif        protected virtual void RemoveSortCore()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
throw new NotSupportedException();
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 返回具有给定 PropertyDescriptor 的行的索引。 </summary>
InBlock.gif        public int Find(PropertyDescriptor property, object key)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return this.FindCore(property, key);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 返回具有给定 PropertyDescriptor 的行的索引。 </summary>
InBlock.gif        protected virtual int FindCore(PropertyDescriptor property, object key)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
throw new NotSupportedException();
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 将 PropertyDescriptor 添加到用于搜索的索引 </summary>
InBlock.gif        void IBindingList.AddIndex(PropertyDescriptor property)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
ExpandedSubBlockEnd.gif
        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 从用于搜索的索引中移除 PropertyDescriptor。 </summary>
InBlock.gif        void IBindingList.RemoveIndex(PropertyDescriptor property)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
ExpandedSubBlockEnd.gif
        }

ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值