【发布时间】:2015-03-22 10:11:27
【问题描述】:
在使用 objectListView treeListView 时,如果我展开了 treeListView 并单击了其中一列中的一个子项,我该怎么做:
- 找到那个孩子的父母?
- 查找已展开列的父行的值/文本?
这个例子可能有助于解释我的意思。
public partial class Form1 : Form
{
List<Contract> list;
public Form1()
{
InitializeComponent();
list = new List<Contract>();
list.Add(new Contract("A", 1));
list.Add(new Contract("B", 2));
foreach (Contract c in list)
{
this.treeListView1.CanExpandGetter = delegate(object x)
{
if (x is Contract)
{
return (((Contract)x).Children.Count > 0);
}
else
{
return false;
}
};
this.treeListView1.ChildrenGetter = delegate(object x)
{
Contract contrat = x as Contract;
return contrat.Children;
};
column1.AspectGetter = delegate(object x)
{
if (x is Contract)
{
return ((Contract)x).Name;
}
else
{
return " ";
}
};
column2.AspectGetter = delegate(object x)
{
if (x is Contract)
{
return ((Contract)x).Value;
}
else
{
Double d = (Double)x;
return d.ToString();
}
};
this.treeListView1.AddObject(c);
}
}
private void treeListView1_CellClick(object sender, BrightIdeasSoftware.CellClickEventArgs e)
{
//NOT SURE WHAT TO DO HERE
}
public void WriteLine(String s)
{
if (this.richTextBox1.TextLength > 0)
{
this.richTextBox1.AppendText(Environment.NewLine);
}
this.richTextBox1.AppendText(s);
}
}
public class Contract
{
public string Name { get; set;}
public Double Value { get; set; }
public List<Double> Children {get; set;}
public Contract(string name, Double value)
{
Name = name;
Value = value;
Children = new List<Double>();
Children.Add(2);
Children.Add(3);
}
}
在 CellClick 事件中,我想同时获取父级和 column1 中父级的值。
【问题讨论】:
标签: c# objectlistview