ObjectListView 嵌套对象
ObjectListView Nested Objects
我目前正在尝试使用 TreeListView,我想知道如何找到三层嵌套对象的值,其中层是位置,然后是系统,然后是设备。
private void initObjectListView()
{
// Can the given object be expanded?
this.treeListView1.CanExpandGetter = delegate(Object x)
{
return x is Location;
};
// What objects should belong underneath the given model object?
this.treeListView1.ChildrenGetter = delegate(Object x)
{
if (x is Location)
return ((Location)x).systemMap.Values;
throw new ArgumentException("Unknown TreeListView Object - Should a Location Type");
};
}
有一个并发字典systemMap(string,Device) 其中string是设备的名字,device本身就是一个设备对象
我已经到了可以替换
的地步
return ((Location)x).systemMap.Values;
和
return ((Location)x).systemMap["System 1"].deviceMap.Values;
我会为我想要的特定系统获得正确的 ListView,但显然我希望它对系统映射中的所有系统完成,而不是系统 1。
return ((Location)x).systemMap.Values;
只显示位置,然后是位置下的系统,但不显示系统下的设备。
谢谢
示例 运行:
型号类:
// column aspect names are the names of these properties
public class AspectBindable
{
public string ObjectName { get; set; }
public string ObjectType { get; set; }
}
// level 2 info
public class Sistem : AspectBindable { public IList <Device> Devices { get; set; } }
//level 1
public class Location : AspectBindable { public IList<Sistem> Systems { get; set; } }
//level 3
public class Device : AspectBindable { }
表单构造函数:
public Form31683555 ( )
{
InitializeComponent();
// control expansion
this.tlv.CanExpandGetter = delegate(object x)
{
if (x is Sistem)
return !ObjectListView.IsEnumerableEmpty((x as Sistem).Devices);
else if (x is Location)
return !ObjectListView.IsEnumerableEmpty((x as Location).Systems);
else if (x is Device)
return false;
else
throw new ArgumentException("x");
};
// node children
this.tlv.ChildrenGetter = delegate(object x) {
if (x is Sistem)
return (x as Sistem).Devices;
else if (x is Location)
return (x as Location).Systems;
else if (x is Device)
return null;
else
throw new ArgumentException("x");
};
// TreeListView first order parent level
this.tlv.Roots = new Location[] {
new Location {
Systems = new Sistem[] {
new Sistem {
Devices = new Device[] {
new Device { ObjectName = "Device 1.1.1", ObjectType="some device"},
new Device { ObjectName = "Device 1.1.2", ObjectType="a device"}
},
ObjectName = "System 1.1", ObjectType = "system"
},
new Sistem {
Devices = new Device[] {
new Device { ObjectName = "Device 1.2.1", ObjectType="device"},
new Device { ObjectName = "Device 1.2.2", ObjectType="another device"}
},
ObjectName = "System 1.2", ObjectType = "another system"
},
},
ObjectType = "location 1", ObjectName="full location"
},
new Location {ObjectName = "empty", ObjectType="location"}
};
}
我目前正在尝试使用 TreeListView,我想知道如何找到三层嵌套对象的值,其中层是位置,然后是系统,然后是设备。
private void initObjectListView()
{
// Can the given object be expanded?
this.treeListView1.CanExpandGetter = delegate(Object x)
{
return x is Location;
};
// What objects should belong underneath the given model object?
this.treeListView1.ChildrenGetter = delegate(Object x)
{
if (x is Location)
return ((Location)x).systemMap.Values;
throw new ArgumentException("Unknown TreeListView Object - Should a Location Type");
};
}
有一个并发字典systemMap(string,Device) 其中string是设备的名字,device本身就是一个设备对象
我已经到了可以替换
的地步return ((Location)x).systemMap.Values;
和
return ((Location)x).systemMap["System 1"].deviceMap.Values;
我会为我想要的特定系统获得正确的 ListView,但显然我希望它对系统映射中的所有系统完成,而不是系统 1。
return ((Location)x).systemMap.Values;
只显示位置,然后是位置下的系统,但不显示系统下的设备。
谢谢
示例 运行:
型号类:
// column aspect names are the names of these properties
public class AspectBindable
{
public string ObjectName { get; set; }
public string ObjectType { get; set; }
}
// level 2 info
public class Sistem : AspectBindable { public IList <Device> Devices { get; set; } }
//level 1
public class Location : AspectBindable { public IList<Sistem> Systems { get; set; } }
//level 3
public class Device : AspectBindable { }
表单构造函数:
public Form31683555 ( )
{
InitializeComponent();
// control expansion
this.tlv.CanExpandGetter = delegate(object x)
{
if (x is Sistem)
return !ObjectListView.IsEnumerableEmpty((x as Sistem).Devices);
else if (x is Location)
return !ObjectListView.IsEnumerableEmpty((x as Location).Systems);
else if (x is Device)
return false;
else
throw new ArgumentException("x");
};
// node children
this.tlv.ChildrenGetter = delegate(object x) {
if (x is Sistem)
return (x as Sistem).Devices;
else if (x is Location)
return (x as Location).Systems;
else if (x is Device)
return null;
else
throw new ArgumentException("x");
};
// TreeListView first order parent level
this.tlv.Roots = new Location[] {
new Location {
Systems = new Sistem[] {
new Sistem {
Devices = new Device[] {
new Device { ObjectName = "Device 1.1.1", ObjectType="some device"},
new Device { ObjectName = "Device 1.1.2", ObjectType="a device"}
},
ObjectName = "System 1.1", ObjectType = "system"
},
new Sistem {
Devices = new Device[] {
new Device { ObjectName = "Device 1.2.1", ObjectType="device"},
new Device { ObjectName = "Device 1.2.2", ObjectType="another device"}
},
ObjectName = "System 1.2", ObjectType = "another system"
},
},
ObjectType = "location 1", ObjectName="full location"
},
new Location {ObjectName = "empty", ObjectType="location"}
};
}