我有3个.net列表项,我需要将它们全部合并为一个,以便对它们进行排序并将它们绑定到数据网格.但是,我需要一种方法来指示每个项目来自哪个原始列表,以便我可以在datagrid中识别它(更改颜色或字体等).
谁能建议最好的方法呢?
List<Foo> list1 = new List<Foo>();
List<Foo> list2 = new List<Foo>();
List<Foo> list3 = new List<Foo>();
var query = list1.Select(foo => new { foo, list = "list1" })
.Concat(list2.Select(foo => new { foo, list = "list2" }))
.Concat(list3.Select(foo => new { foo, list = "list3" }))
.OrderBy(item => item.foo); // whatever you need to order by
Run Code Online (Sandbox Code Playgroud)
根据需要展开属性.