locked
count number of items RRS feed

  • Question

  • I want to do a simple of count of item from a filtered table or items collection...

    Using the ToDo Sample form Azure mobile services how could I achieve this?

       private void RefreshTodoItems()
            {
                // This code refreshes the entries in the list view be querying the TodoItems table.
                // The query excludes completed TodoItems
                items = todoTable
                    .Where(todoItem => todoItem.Complete == false)
                    .ToCollectionView();
                ListItems.ItemsSource = items;
            }

    Friday, February 22, 2013 9:36 PM

Answers

  • You can use

    listview.Items.Count to count items.


    Thanks, Sachin

    • Marked as answer by Andy Sid Saturday, February 23, 2013 1:39 AM
    Saturday, February 23, 2013 1:21 AM

All replies

  • Most of the posts I've seen say that you must iterate over the collection. Or they say you need to convert to a List<> object to get a count.

    With my experiments, all three approaches resulted in a correct result:

    IEnumerable<SampleDataGroup> items = this.AllGroups.Where(myitem => myitem.UniqueId.Contains("Group"));
    int theCount = items.Count();
    
    List<SampleDataGroup> mylist = items.ToList<SampleDataGroup>();
    int theCount2 = mylist.Count;
    
    int result = 0;
    using (IEnumerator<SampleDataGroup> enumerator = items.GetEnumerator())
    {
        while (enumerator.MoveNext())
            result++;
    }
    int theCount3 = result;
    

    Friday, February 22, 2013 11:59 PM
  • Thanks. Is there a way to count items in a listview?
    Saturday, February 23, 2013 12:53 AM
  • You can use

    listview.Items.Count to count items.


    Thanks, Sachin

    • Marked as answer by Andy Sid Saturday, February 23, 2013 1:39 AM
    Saturday, February 23, 2013 1:21 AM