无为清净楼资源网 Design By www.qnjia.com
IHierarchicalDataSource实现:
public class InsHierarchyData : IHierarchyData, ICustomTypeDescriptor
{
private DataRowView item;
private string dataParentIdField;
private string dataIdField;
private string displayField;
public InsHierarchyData(string dataParentIdField, string dataIdField,string displayField, DataRowView item)
{
this.item = item;
this.dataParentIdField = dataParentIdField;
this.dataIdField = dataIdField;
this.displayField = displayField;
}
bool IHierarchyData.HasChildren
{
get
{
foreach (DataRowView row in item.DataView)
{
object[] array1 = row.Row.ItemArray;
object[] array2 = item.Row.ItemArray;
string a = row[dataParentIdField].ToString();
string b = item[dataIdField].ToString();
if (a == b)
return true;
}
return false;
}
}
object IHierarchyData.Item
{
get
{
return item;
}
}
public override string ToString()
{
return item[displayField].ToString();
}
string IHierarchyData.Path
{
get
{
string path = "/*[position()=1]";
GetPath(item, ref path);
return path;
}
}
void GetPath(DataRowView crow, ref string path)
{
foreach (DataRowView row in item.DataView)
{
string c, d;
c = crow.Row.ItemArray[2].ToString();
d = crow.Row.ItemArray[0].ToString();
string a = crow[dataParentIdField].ToString();
string b = row[dataIdField].ToString();
if (a == b)
{
path = "/*[position()=1]" + path;
}
}
}
string IHierarchyData.Type
{
get { return displayField; }
}
IHierarchicalEnumerable IHierarchyData.GetChildren()
{
InsHierarchicalEnumerable children = new InsHierarchicalEnumerable();
foreach (DataRowView row in item.DataView)
{
string a = row[dataParentIdField].ToString();
string b = item[dataIdField].ToString();
if (a == b)
children.Add(new InsHierarchyData(dataParentIdField, dataIdField,displayField, row));
}
return children;
}
IHierarchyData IHierarchyData.GetParent()
{
foreach (DataRowView row in item.DataView)
{
string a = item[dataParentIdField].ToString();
string b = row[dataIdField].ToString();
if (a == b)
return new InsHierarchyData(dataParentIdField, dataIdField,displayField, row);
}
return null;
}
System.ComponentModel.AttributeCollection ICustomTypeDescriptor.GetAttributes()
{
return TypeDescriptor.GetAttributes(this, true);
}
string ICustomTypeDescriptor.GetClassName()
{
return TypeDescriptor.GetClassName(this, true);
}
string ICustomTypeDescriptor.GetComponentName()
{
return TypeDescriptor.GetComponentName(this, true);
}
TypeConverter ICustomTypeDescriptor.GetConverter()
{
return TypeDescriptor.GetConverter(this, true);
}
EventDescriptor ICustomTypeDescriptor.GetDefaultEvent()
{
return TypeDescriptor.GetDefaultEvent(this, true);
}
PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty()
{
return TypeDescriptor.GetDefaultProperty(this, true);
}
object ICustomTypeDescriptor.GetEditor(Type editorBaseType)
{
return TypeDescriptor.GetEditor(this, editorBaseType, true);
}
EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes)
{
return TypeDescriptor.GetEvents(this, attributes, true);
}
EventDescriptorCollection ICustomTypeDescriptor.GetEvents()
{
return TypeDescriptor.GetEvents(this, true);
}
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
{
PropertyDescriptorCollection pds = TypeDescriptor.GetProperties(item);
if (pds.Count > 0)
{
List<InsHierarchyDataPropertyDescriptor> list = new List<InsHierarchyDataPropertyDescriptor>();
foreach (PropertyDescriptor pd in pds)
{
list.Add(new InsHierarchyDataPropertyDescriptor(pd.Name));
}
InsHierarchyDataPropertyDescriptor[] arr = new InsHierarchyDataPropertyDescriptor[list.Count];
list.CopyTo(arr);
return new PropertyDescriptorCollection(arr);
}
return PropertyDescriptorCollection.Empty;
}
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
{
return ((ICustomTypeDescriptor)this).GetProperties(null);
}
object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd)
{
if (pd is InsHierarchyDataPropertyDescriptor)
{
return this;
}
return null;
}
}
public class InsHierarchyDataPropertyDescriptor : PropertyDescriptor
{
private string name;
public InsHierarchyDataPropertyDescriptor(string name)
: base(name, null)
{
this.name = name;
}
public override string Name
{
get { return name; }
}
public override Type ComponentType
{
get
{
return typeof(InsHierarchyData);
}
}
public override bool IsReadOnly
{
get
{
return true;
}
}
public override Type PropertyType
{
get
{
return Type.GetType("System.String");
}
}
public override bool CanResetValue(object o)
{
return false;
}
public override object GetValue(object o)
{
InsHierarchyData shd = o as InsHierarchyData;
if (shd != null)
{
IHierarchyData hd = (IHierarchyData)shd;
string subject = ((DataRowView)(hd.Item))[name].ToString();
return subject;
}
return null;
}
public override void ResetValue(object o)
{
throw new NotSupportedException();
}
public override void SetValue(object o, object value)
{
throw new NotSupportedException();
}
public override bool ShouldSerializeValue(object o)
{
return true;
}
public override TypeConverter Converter
{
get { return TypeDescriptor.GetConverter(typeof(System.String)); }
}
}
public class InsHierarchicalEnumerable : ArrayList, IHierarchicalEnumerable
{
IHierarchyData IHierarchicalEnumerable.GetHierarchyData(object enumeratedItem)
{
return (InsHierarchyData)enumeratedItem;
}
}
public class InsHierarchicalDataSourceView : HierarchicalDataSourceView
{
string viewPath;
InsTreeViewDataSource owner;
public InsHierarchicalDataSourceView(InsTreeViewDataSource owner, string viewPath)
{
this.viewPath = viewPath;
this.owner = owner;
}
public override IHierarchicalEnumerable Select()
{
//DataView dv = (DataView)this.owner.Select(DataSourceSelectArguments.Empty);
DataView dv = (DataView)this.owner.DataView;
InsHierarchicalEnumerable data = new InsHierarchicalEnumerable();
bool hasParent = false;
foreach (DataRowView crow in dv)
{
object[] array1 = crow.Row.ItemArray;
hasParent = false;
foreach (DataRowView prow in dv)
{
object[] array2 = prow.Row.ItemArray;
//子节点
string a = crow[owner.DataParentIdField].ToString();
//根节点
string b = prow[owner.DataIdField].ToString();
if (a == b)
{
hasParent = true;
break;
}
}
//添加根节点
if (!hasParent)
data.Add(new InsHierarchyData(owner.DataParentIdField, owner.DataIdField, owner.DisplayField, crow));
}
return data;
}
}
public class InsTreeViewDataSource : IHierarchicalDataSource
{
private InsHierarchicalDataSourceView view = null;
private string parentIdField;
private string idField;
private DataTable dataSource;
private string displayField;
public InsTreeViewDataSource(string parentIdField, string idField, string displayField,DataTable dataSource)
{
this.parentIdField = parentIdField;
this.idField = idField;
this.displayField = displayField;
this.dataSource = dataSource;
}
public DataView DataView
{
get
{
return this.dataSource.DefaultView;
}
}
HierarchicalDataSourceView IHierarchicalDataSource.GetHierarchicalView(string viewPath)
{
if (null == this.view)
this.view = new InsHierarchicalDataSourceView(this, viewPath);
return this.view;
}
public string DataParentIdField
{
get { return parentIdField; }
set { parentIdField = value; }
}
public string DataIdField
{
get { return idField; }
set { idField = value; }
}
public string DisplayField
{
get { return displayField; }
set { displayField = value; }
}
public event EventHandler DataSourceChanged;
}
客户端代码:
DataTable dt = null;//自定义数据源
InsTreeViewDataSource dataSource = new InsTreeViewDataSource("Parent_Id", "ID", "FULL_NAME", dt);
this.itvTree.DataSource = dataSource;
this.itvTree.DataBind();
public class InsHierarchyData : IHierarchyData, ICustomTypeDescriptor
{
private DataRowView item;
private string dataParentIdField;
private string dataIdField;
private string displayField;
public InsHierarchyData(string dataParentIdField, string dataIdField,string displayField, DataRowView item)
{
this.item = item;
this.dataParentIdField = dataParentIdField;
this.dataIdField = dataIdField;
this.displayField = displayField;
}
bool IHierarchyData.HasChildren
{
get
{
foreach (DataRowView row in item.DataView)
{
object[] array1 = row.Row.ItemArray;
object[] array2 = item.Row.ItemArray;
string a = row[dataParentIdField].ToString();
string b = item[dataIdField].ToString();
if (a == b)
return true;
}
return false;
}
}
object IHierarchyData.Item
{
get
{
return item;
}
}
public override string ToString()
{
return item[displayField].ToString();
}
string IHierarchyData.Path
{
get
{
string path = "/*[position()=1]";
GetPath(item, ref path);
return path;
}
}
void GetPath(DataRowView crow, ref string path)
{
foreach (DataRowView row in item.DataView)
{
string c, d;
c = crow.Row.ItemArray[2].ToString();
d = crow.Row.ItemArray[0].ToString();
string a = crow[dataParentIdField].ToString();
string b = row[dataIdField].ToString();
if (a == b)
{
path = "/*[position()=1]" + path;
}
}
}
string IHierarchyData.Type
{
get { return displayField; }
}
IHierarchicalEnumerable IHierarchyData.GetChildren()
{
InsHierarchicalEnumerable children = new InsHierarchicalEnumerable();
foreach (DataRowView row in item.DataView)
{
string a = row[dataParentIdField].ToString();
string b = item[dataIdField].ToString();
if (a == b)
children.Add(new InsHierarchyData(dataParentIdField, dataIdField,displayField, row));
}
return children;
}
IHierarchyData IHierarchyData.GetParent()
{
foreach (DataRowView row in item.DataView)
{
string a = item[dataParentIdField].ToString();
string b = row[dataIdField].ToString();
if (a == b)
return new InsHierarchyData(dataParentIdField, dataIdField,displayField, row);
}
return null;
}
System.ComponentModel.AttributeCollection ICustomTypeDescriptor.GetAttributes()
{
return TypeDescriptor.GetAttributes(this, true);
}
string ICustomTypeDescriptor.GetClassName()
{
return TypeDescriptor.GetClassName(this, true);
}
string ICustomTypeDescriptor.GetComponentName()
{
return TypeDescriptor.GetComponentName(this, true);
}
TypeConverter ICustomTypeDescriptor.GetConverter()
{
return TypeDescriptor.GetConverter(this, true);
}
EventDescriptor ICustomTypeDescriptor.GetDefaultEvent()
{
return TypeDescriptor.GetDefaultEvent(this, true);
}
PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty()
{
return TypeDescriptor.GetDefaultProperty(this, true);
}
object ICustomTypeDescriptor.GetEditor(Type editorBaseType)
{
return TypeDescriptor.GetEditor(this, editorBaseType, true);
}
EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes)
{
return TypeDescriptor.GetEvents(this, attributes, true);
}
EventDescriptorCollection ICustomTypeDescriptor.GetEvents()
{
return TypeDescriptor.GetEvents(this, true);
}
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
{
PropertyDescriptorCollection pds = TypeDescriptor.GetProperties(item);
if (pds.Count > 0)
{
List<InsHierarchyDataPropertyDescriptor> list = new List<InsHierarchyDataPropertyDescriptor>();
foreach (PropertyDescriptor pd in pds)
{
list.Add(new InsHierarchyDataPropertyDescriptor(pd.Name));
}
InsHierarchyDataPropertyDescriptor[] arr = new InsHierarchyDataPropertyDescriptor[list.Count];
list.CopyTo(arr);
return new PropertyDescriptorCollection(arr);
}
return PropertyDescriptorCollection.Empty;
}
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
{
return ((ICustomTypeDescriptor)this).GetProperties(null);
}
object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd)
{
if (pd is InsHierarchyDataPropertyDescriptor)
{
return this;
}
return null;
}
}
public class InsHierarchyDataPropertyDescriptor : PropertyDescriptor
{
private string name;
public InsHierarchyDataPropertyDescriptor(string name)
: base(name, null)
{
this.name = name;
}
public override string Name
{
get { return name; }
}
public override Type ComponentType
{
get
{
return typeof(InsHierarchyData);
}
}
public override bool IsReadOnly
{
get
{
return true;
}
}
public override Type PropertyType
{
get
{
return Type.GetType("System.String");
}
}
public override bool CanResetValue(object o)
{
return false;
}
public override object GetValue(object o)
{
InsHierarchyData shd = o as InsHierarchyData;
if (shd != null)
{
IHierarchyData hd = (IHierarchyData)shd;
string subject = ((DataRowView)(hd.Item))[name].ToString();
return subject;
}
return null;
}
public override void ResetValue(object o)
{
throw new NotSupportedException();
}
public override void SetValue(object o, object value)
{
throw new NotSupportedException();
}
public override bool ShouldSerializeValue(object o)
{
return true;
}
public override TypeConverter Converter
{
get { return TypeDescriptor.GetConverter(typeof(System.String)); }
}
}
public class InsHierarchicalEnumerable : ArrayList, IHierarchicalEnumerable
{
IHierarchyData IHierarchicalEnumerable.GetHierarchyData(object enumeratedItem)
{
return (InsHierarchyData)enumeratedItem;
}
}
public class InsHierarchicalDataSourceView : HierarchicalDataSourceView
{
string viewPath;
InsTreeViewDataSource owner;
public InsHierarchicalDataSourceView(InsTreeViewDataSource owner, string viewPath)
{
this.viewPath = viewPath;
this.owner = owner;
}
public override IHierarchicalEnumerable Select()
{
//DataView dv = (DataView)this.owner.Select(DataSourceSelectArguments.Empty);
DataView dv = (DataView)this.owner.DataView;
InsHierarchicalEnumerable data = new InsHierarchicalEnumerable();
bool hasParent = false;
foreach (DataRowView crow in dv)
{
object[] array1 = crow.Row.ItemArray;
hasParent = false;
foreach (DataRowView prow in dv)
{
object[] array2 = prow.Row.ItemArray;
//子节点
string a = crow[owner.DataParentIdField].ToString();
//根节点
string b = prow[owner.DataIdField].ToString();
if (a == b)
{
hasParent = true;
break;
}
}
//添加根节点
if (!hasParent)
data.Add(new InsHierarchyData(owner.DataParentIdField, owner.DataIdField, owner.DisplayField, crow));
}
return data;
}
}
public class InsTreeViewDataSource : IHierarchicalDataSource
{
private InsHierarchicalDataSourceView view = null;
private string parentIdField;
private string idField;
private DataTable dataSource;
private string displayField;
public InsTreeViewDataSource(string parentIdField, string idField, string displayField,DataTable dataSource)
{
this.parentIdField = parentIdField;
this.idField = idField;
this.displayField = displayField;
this.dataSource = dataSource;
}
public DataView DataView
{
get
{
return this.dataSource.DefaultView;
}
}
HierarchicalDataSourceView IHierarchicalDataSource.GetHierarchicalView(string viewPath)
{
if (null == this.view)
this.view = new InsHierarchicalDataSourceView(this, viewPath);
return this.view;
}
public string DataParentIdField
{
get { return parentIdField; }
set { parentIdField = value; }
}
public string DataIdField
{
get { return idField; }
set { idField = value; }
}
public string DisplayField
{
get { return displayField; }
set { displayField = value; }
}
public event EventHandler DataSourceChanged;
}
客户端代码:
DataTable dt = null;//自定义数据源
InsTreeViewDataSource dataSource = new InsTreeViewDataSource("Parent_Id", "ID", "FULL_NAME", dt);
this.itvTree.DataSource = dataSource;
this.itvTree.DataBind();
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年11月15日
2024年11月15日
- 文章.2004-被遗忘的时光【华博音乐】【WAV+CUE】
- 群星《青葱韶歌》原力计划·毕业季企划合辑[FLAC+分轨][661M]
- 群星《抖烧 DSD》抖音神曲 [WAV分轨][992M]
- 庾澄庆《哈林天堂》索尼音乐[WAV+CUE][1G]
- 英雄联盟全球总决赛多久打一次 全球总决赛举办频率介绍
- 第二届老头杯什么时候开始选人 第二届老头杯选人时间介绍
- 英雄联盟第二届老头杯什么时候开始 老头杯s2赛程时间队伍名单汇总
- AI赋能卓越显示技术共筑数字未来:三星显示器产品矩阵亮相2024进博会
- 技术剖析:天玑9400如何打造移动最强GPU和游戏体验?
- 顶级装备 实力登顶:三星显示器双十一焕新升级最后冲刺
- 陈影《绝色靓声》WAV+CUE
- 龚玥《禅是一枝花(6N纯银SQCD)》原抓WAV+CUE
- 刘德丽《寂寞在唱歌HQCD+A2HD5》[WAV+CUE]
- 萧亚轩《钻石糖》金牌大风[WAV+CUE][989M]
- 王菲《王菲精选-菲卖品》环球唱片SHM-SACD[ISO][1.9G]