English 中文(简体)
合并多个清单
原标题:Combining multiple lists

我有5套清单,我将不得不管理5套不同的校对清单。 我也想在需要一个“综合”清单才能具有约束力的数据网中显示这些清单的进展情况。

不能确定从哪里开始。 如果我使用目录,如果我删除该分项,则将不更新括号。

public partial class MainWindow : Window
{


    ObservableCollection<TestObject> _combinedList = new ObservableCollection<TestObject>();
    public ObservableCollection<TestObject> CombinedList
    {
        get
        {
            return _combinedList;
        }
        set
        {
            _combinedList = value;
        }
    }


    List<TestObject> _list1 = new List<TestObject>();
    List<TestObject> _list2 = new List<TestObject>();
    List<TestObject> _list3 = new List<TestObject>();
    List<TestObject> _list4 = new List<TestObject>();
    List<TestObject> _list5 = new List<TestObject>();


    public MainWindow()
    {
        InitializeComponent();

        dataGridCombined.ItemsSource = CombinedList;

    }

    private void cmdCreateLists_Click(object sender, RoutedEventArgs e)
    {
        createLists();
    }

    public void createLists()
    {
        for (int i = 1; i < 6; i++)
        {
            _list1.Add(new TestObject(i));
        }

        for (int i = 1; i < 6; i++)
        {
            _list2.Add(new TestObject(i*3));
        }

        for (int i = 1; i < 6; i++)
        {
            _list3.Add(new TestObject(i*5));
        }

        for (int i = 1; i < 6; i++)
        {
            _list4.Add(new TestObject(i*7));
        }

        for (int i = 1; i < 6; i++)
        {
            _list5.Add(new TestObject(i*9));
        }

    }

    private void cmdMergeLists_Click(object sender, RoutedEventArgs e)
    {
        //Doesn t work and if i remove item from sublist, CombinedList doesn t update.
        CombinedList = _list1.Concat<TestObject>(_list2);


    }

}

public class TestObject : BindableObject
{
    private int _number;
    public int Number
    {
        get
        {
            return _number;
        }
        set
        {
            _number = value;
            RaisePropertyChanged("Number");
        }
    }

    private string _name;
    public string Name
    {
        get
        {
            return _name;
        }
        set
        {
            _name = value;
            RaisePropertyChanged("Name");
        }
    }

    public TestObject(int inNum)
    {
        _number = inNum;
        _name = "John";
    }

}

我不得不在这里撰写某种习俗汇编?

关于

最佳回答

首先,在<代码>上添加所有项目。 ObservableCollection<T>。 这将提供综合名单。

如果我使用目录,如果我删除该分项,则将不更新括号。

您可以订阅ObservableCollection<T>CollectionChanged,“combined”藏书,并在发生变动时添加或删除适当的背书。

问题回答

Use AddRange vs individual calls to Add()

或者,只有一份由所有线索提供,并且从每个线上增加,而不是将5个单独收集汇编结合起来。

您可作附加说明的概述:

var combined = list1.Select(i => new {
        Item = i,
        Origin = list1 }).Concat(
  list2.Select(i => new {
        Item = i,
        Origin = list2 }))
 .ToList(); // TODO extend for more lists

这样,你就可以获得一份物品清单:

combined[13].Origin.Remove(combined[13]);
// refresh combined list!

Just use CompositeCollection。 您可以添加任何物品,包括其他收藏品,并且受其约束的管制将获得所有物品的统一看法。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签