本文介绍了使用MVVM的Silverlight ListBox分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在列表框中分组时出现问题.实际上我的表结构如下.

Emp_ID EmpName EmpParent_ID

1000002 Vivek 1000005
1000003罗希特1000005
1000005阿贾伊1000031
1000006 Sanjay 1000005
1000011 Hemant -1
1000022 Amit 1000005
1000024 Aakash 1000006
1000027 Ameya 1000005
1000030拉姆1000005
1000042 Arvind -1

现在,我想对EmpParent_ID进行分组.输出应如下所示:

阿贾伊
Vivek
罗希特
桑杰伊
阿米特
阿美亚
公羊
桑杰伊
阿卡什

如果使用ListBox无法做到这一点,那么请建议我以其他方式使其正常工作...

I have problem while grouping in listbox. Actually my table structure is as follows.

Emp_ID EmpName EmpParent_ID

1000002 Vivek 1000005
1000003 Rohit 1000005
1000005 Ajay 1000031
1000006 Sanjay 1000005
1000011 Hemant -1
1000022 Amit 1000005
1000024 Aakash 1000006
1000027 Ameya 1000005
1000030 Ram 1000005
1000042 Arvind -1

Now I want to group on EmpParent_ID. Output should be like this:

Ajay
Vivek
Rohit
Sanjay
Amit
Ameya
Ram
Sanjay
Aakash

If this is not possible using ListBox then please suggest me other way to work it properly...

推荐答案

class Program
{
    static void Main(string[] args)
    {
        List<person> pessoas = new List<person>()
        {
            new Person(){ id = 1, name = "fernando"},
            new Person(){ id = 2, name = "rodrigo"},
            new Person(){ id = 4, name = "fernando"},
            new Person(){ id = 5, name = "rogerio"},
            new Person(){ id = 6, name = "fernando"},
            new Person(){ id = 7, name = "davi"}
        };

        foreach (Person pes in pessoas.Distinct(new CustomComparer()))
        {
            Console.WriteLine(pes.name);
        }

        Console.Read();
    }
}

public class Person
{
    public int id { get; set; }
    public string name { get; set; }
}

public class CustomComparer : IEqualityComparer<person>
{
    public bool Equals(Person x, Person y)
    {
        return x.name.Equals(y.name);
    }

    public int GetHashCode(Person obj)
    {
        return this.GetHashCode();
    }
}</person></person></person>


这篇关于使用MVVM的Silverlight ListBox分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 07:37