Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
425
How to get a column's distinct value list in xamgrid?
posted

Hello,

Now i want to get a list of data from the existed rows in the xamgrid's column, is there any API to get it?

 

For example, there are 5 rows in the xamgrid

           Country

1          UK

2          USA

3          USA

4          UK

5          UK

 

I want to get a list   List<string> countries.    How could I get it?

 

Parents
No Data
Reply
  • 21382
    Suggested Answer
    posted

    Since the grid is bound, the most efficient route would most likely be to get the data off your data model itself rather then through the grid.  

     

    Something like this

     

                List<Person> list = new List<Person>();

                list.Add(new Person() { StateCode = "NJ" });

                list.Add(new Person() { StateCode = "NJ" });

                list.Add(new Person() { StateCode = "NY" });

                list.Add(new Person() { StateCode = "PA" });

                list.Add(new Person() { StateCode = "NY" });

                IEnumerable<string> stateCodes =list.Select( a => a.StateCode );

                stateCodes =stateCodes.Distinct().ToList();

     

    This way you skip using the grid and the overhead associated with navigating the entire collection via the grid.

Children