locked
How sorting the items in GridView without ItemTemplate

    Question

  • Hi All,

    I have added more than 100 GridViewItem in GridView dynamically. I need to Sorting that items by ascending as well as descending order. How do we do that. Please help me ASAP.


    Thanks by Manivel


    • Edited by Manivelp Tuesday, May 14, 2013 5:53 AM
    Tuesday, May 14, 2013 5:52 AM

Answers

  • But i think you need to use data source when you need to sort it. Instead of adding items directly into GridView use something like:

    auto items = ref new Vector<Object^>();
    items->Append( item_to_show);
    grid->ItemsSource = items;

    and when you need to sort data:

    template<class T>
    struct compare {
    	bool operator ()(T left, T right) const {
    		return left < right;
    	}
    };
    
    std::sort(begin(items), end(items), compare<T>());
    

    • Marked as answer by Jesse Jiang Monday, May 20, 2013 8:18 AM
    Tuesday, May 14, 2013 8:54 AM

All replies

  • You need to sort source data set (e.g. vector assigned to CollectionSource or as ItemsSource).
    Tuesday, May 14, 2013 7:09 AM
  • Thanks Petr,

    But i am not using any data source. Then how can i sort the data source. I am adding the gridviewitem to gridview.


    Thanks by Manivel

    Tuesday, May 14, 2013 8:37 AM
  • But i think you need to use data source when you need to sort it. Instead of adding items directly into GridView use something like:

    auto items = ref new Vector<Object^>();
    items->Append( item_to_show);
    grid->ItemsSource = items;

    and when you need to sort data:

    template<class T>
    struct compare {
    	bool operator ()(T left, T right) const {
    		return left < right;
    	}
    };
    
    std::sort(begin(items), end(items), compare<T>());
    

    • Marked as answer by Jesse Jiang Monday, May 20, 2013 8:18 AM
    Tuesday, May 14, 2013 8:54 AM