我建立了一个treeListView:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TreeListViewTest1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.treeListView1.CanExpandGetter = delegate(object x)
{
return true;
};
this.treeListView1.ChildrenGetter = delegate(object x)
{
Contract contract = 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(new Contract("A", 1));
}
private void treeListView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
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);
}
}
}
它给出了这个输出:
Name Value
A 1
2
3
如何从事件中更新父项和子项的 column2(“值”)值?(增加父母和孩子的每个价值。)
private void button1_Click(object sender, EventArgs e)
{
}
我不明白我是否必须再次使用 AspectGetter,或者我是否可以以某种方式只修改 column2 中的值,然后再 refreshObjects()。