我有一个树视图,显示Company
类型的对象层次结构。
Company
(以及其他)属性Bool? Checked
。我在每行的复选框中使用该值。我希望复选框(也)指示是否已选择任何子项,但我不确定如何为Getter
属性构建Checked
。
我想问题是该值不仅代表当前对象的值,还代表子代的组合值。它是可以解决的还是我需要重新思考?
这是我想得到的结果:
班级公司:
public class Company
{
public Company()
{
this.childs = new List<Company>();
}
public int ID { get; set; }
public string Title { get; set; }
public List<Company> childs { get; set; }
public int NrOfChilds { get { return childs.Count; } }
public bool Checked {
get { ??? }
set { this.Checked = value; }
}
答案 0 :(得分:1)
好的,所以使用可空的bool是一个OLV要求吗?
但这不应该能达到你想要的效果吗?
class Entity {
private bool? _CheckState;
public List<Entity> ChildEntities { get; set; }
public Entity() {
_CheckState = false;
ChildEntities = new List<Entity>();
}
public bool? CheckState {
get {
if (_CheckState == true) {
return true;
} else if (ChildEntities.All(child => child.CheckState == false)) {
return false;
} else {
return null;
}
}
set { _CheckState = value; }
}
}