locked
Dropped GridViewItem in GridView

    Question

  • How to get the index of GridviewItem in Gridview while dropping item?
    Friday, September 07, 2012 5:10 AM

Answers

  • Hello,

    First, you should add
    CanDragItems="True" CanReorderItems="True" AllowDrop="True"
    In GridView so that the item can be dropped.

    Then, the Drop event would not handle the drop event. You should use itemsChangedEventHandler when user drop and change the item.
    Pleaser add these codes in your project.

    	mygrid->ItemContainerGenerator->ItemsChanged+=ref new Windows::UI::Xaml::Controls::Primitives::ItemsChangedEventHandler(this,&MainPage::ItemsChangedEventHandler);
    
    
    
    
    
    void animateitem::MainPage::ItemsChangedEventHandler(Object^ sender, ItemsChangedEventArgs^ e)
    {
    	GeneratorPosition gp=e->Position;
    	int i=gp.Index;
    	
    }

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Jesse Jiang Thursday, September 13, 2012 3:13 AM
    Tuesday, September 11, 2012 8:44 AM

All replies

  • The following post "Xaml GridView Reorder Events" [CSharp/VB, unfortunately not in C++] gives you a working example with some insight about how to get the index at Drop complete, not whilst DragDrop is in progress.  It is possibly sufficient information for your scenario.

    The relevant code that provides information is located in:

    - itemList.CollectionChanged += itemList_CollectionChanged; // occurs whether CVS is used or not
    - viewSource.View.VectorChanged += View_VectorChanged; // occurs only if CVS is used

    Friday, September 07, 2012 5:47 AM
  • Thanks, I need only the Dropped item index in grid view. (don't need to insert an item while dropping). Please Help

    Can we get the Item index from Item panel?

    • Edited by AnilKumar.S Monday, September 10, 2012 10:56 AM Very Urgent
    Monday, September 10, 2012 10:55 AM
  • Hello,

    First, you should add
    CanDragItems="True" CanReorderItems="True" AllowDrop="True"
    In GridView so that the item can be dropped.

    Then, the Drop event would not handle the drop event. You should use itemsChangedEventHandler when user drop and change the item.
    Pleaser add these codes in your project.

    	mygrid->ItemContainerGenerator->ItemsChanged+=ref new Windows::UI::Xaml::Controls::Primitives::ItemsChangedEventHandler(this,&MainPage::ItemsChangedEventHandler);
    
    
    
    
    
    void animateitem::MainPage::ItemsChangedEventHandler(Object^ sender, ItemsChangedEventArgs^ e)
    {
    	GeneratorPosition gp=e->Position;
    	int i=gp.Index;
    	
    }

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Jesse Jiang Thursday, September 13, 2012 3:13 AM
    Tuesday, September 11, 2012 8:44 AM