1

私は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 ("Value") の値を更新するにはどうすればよいですか? (親と子のそれぞれの値を増やします。)

private void button1_Click(object sender, EventArgs e)
{

}

AspectGetter を再度使用する必要があるのか​​、またはどうにかして column2 の値だけを変更してから refreshObjects() できるのかわかりません。

4

1 に答える 1

3

AspectGetter を再度使用する必要があるのか​​、またはどうにかして column2 の値だけを変更してから refreshObjects() できるのかわかりません。

いいえ、基礎となるモデルオブジェクトを操作して、treeListView1.RefreshObject(myObject);たとえば、どこにあるmyObjectべきかを呼び出す必要がありContractます。これにより、それぞれの行の内容が更新されます。

あなたの button1_Click() が何をすべきかはわかりませんが、更新したいオブジェクトの参照が明らかに必要です。これは、現在選択されているオブジェクト ( treeListView.SelectedObject) などです。やりたいことを教えていただければ、より多くの情報を提供できるかもしれません。

于 2014-08-19T11:42:28.827 に答える