/// <summary> /// 当单元格失去焦点之后,统一调用单元格类的对应函数; /// </summary> /// <param name="name"></param> /// <returns></returns> public bool JudgePropertyName_ChangeSelection(string name, object SelectionObj) { bool ret = false; // 在当前列名于属性列表中查找,看是否有匹配项; if (ColName_Property.ContainsKey(name)) { string key = ColName_Property[name]; if (Properties.ContainsKey(key)) { object property = Properties[key]; (property as AbsDataGridCell).SelectionCellChanged(SelectionObj); return(true); } } else { Console.WriteLine("Can not find the right property"); return(false); } return(ret); }
// 为动态类型动态添加方法; public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) { // 可以通过调用方法的手段添加属性,AddProperty方法一共有三个参数; // 参数1:属性的名称; // 参数2:属性的实例值; // 参数3:列名称与属性之间建立关系; if (binder.Name == "AddProperty" && binder.CallInfo.ArgumentCount == 3) { string name = args[0] as string; if (name == null) { //throw new ArgumentException("name"); result = null; return(false); } // 向属性列表添加属性及其值; object value = args[1]; Properties.Add(name, value); // 添加列名与属性列表的映射关系; string column_name = args[2] as string; ColName_Property.Add(column_name, name); PropertyList.Add(new Tuple <string, string, object>(name, column_name, value)); result = value; return(true); } if (binder.Name == "GetProperty" && binder.CallInfo.ArgumentCount == 1) { string columnname = args[0] as string; if (columnname == null) { result = null; return(false); } // 在当前列名于属性列表中查找,看是否有匹配项; if (ColName_Property.ContainsKey(columnname)) { string key = ColName_Property[columnname]; if (Properties.ContainsKey(key)) { object property = Properties[key]; result = property; return(true); } } else { Console.WriteLine("Can not find the right property"); result = null; return(false); } } // 判断单元格是否正在被编辑; if (binder.Name == "JudgePropertyName_StartEditing" && binder.CallInfo.ArgumentCount == 1) { string columnname = args[0] as string; if (columnname == null) { result = null; return(false); } // 在当前列名于属性列表中查找,看是否有匹配项; if (ColName_Property.ContainsKey(columnname)) { string key = ColName_Property[columnname]; if (Properties.ContainsKey(key)) { object property = Properties[key]; (property as AbsDataGridCell).EditingCallback(); result = property; return(true); } } else { Console.WriteLine("Can not find the right property"); result = null; return(false); } } return(base.TryInvokeMember(binder, args, out result)); }