locked
Dragging in gridview

    Question

  • Iam trying to drag an item from grid view to a grid .I am trying in Dragenter,DragLeave,Dragover and Drop events. Is anyone have idea about this..?

    please provide me sample code in metro app using c ++ language.

    Regards,

    Sarath s

    Monday, August 20, 2012 2:03 PM

Answers

  • Hello,

    Unfortunately we don't have sample code for every scenario. We really prefer if developers ask a specific question. Example: "How do I get the gird item that I want to transfer to the drop target". If you follow these guidelines in future posts you will likely get better a faster responses.

    That said, I did writer this code for you because I think it will benefit others as well:

            <GridView x:Name="_gf" IsItemClickEnabled="True" Background="Gray" HorizontalAlignment="Left" Margin="51,45,0,0" VerticalAlignment="Top" Width="297" Height="443" AllowDrop="True" CanReorderItems="True" CanDragItems="True" DragItemsStarting="_gf_DragItemsStarting" >
                <GridViewItem BorderBrush="Black" Content="This is a test"/>
                <GridViewItem BorderBrush="Black" Content="This is a test"/>
                <GridViewItem BorderBrush="Black" Content="This is a test"/>
                <GridViewItem BorderBrush="Black" Content="This is a test"/>
                <GridViewItem BorderBrush="Black" Content="This is a test"/>
                <GridViewItem BorderBrush="Black" Content="This is a test"/>
                <GridViewItem BorderBrush="Black" Content="This is a test"/>
            </GridView>
            <GridView x:Name="_gt" Background="black" HorizontalAlignment="Left" Margin="386,45,0,0" VerticalAlignment="Top" Width="297" Height="443" AllowDrop="True" CanDragItems="True" CanReorderItems="True" Drop="_gt_Drop"/>


    void DragAndDropCPP::MainPage::_gf_DragItemsStarting(Platform::Object^ sender, Windows::UI::Xaml::Controls::DragItemsStartingEventArgs^ e)
    {
    	e->Data->Properties->Insert("item", e->Items->GetAt(0));
    }
    void DragAndDropCPP::MainPage::_gt_Drop(Platform::Object^ sender, Windows::UI::Xaml::DragEventArgs^ e)
    {
    	_gt->Items->Append(e->Data->Properties->Lookup("item"));
    }

    I hope this helps,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Thursday, August 23, 2012 11:01 PM
    Moderator

All replies

  • Hello,

    Does this article help?

    http://msdn.microsoft.com/en-us/library/windows/apps/Hh465173

    -James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Wednesday, August 22, 2012 1:09 AM
    Moderator
  • hi

    please provide me sample for dragging in gridview using above events.

    Regards,

    Sarath s

    Wednesday, August 22, 2012 9:34 AM
  • Hello,

    Unfortunately we don't have sample code for every scenario. We really prefer if developers ask a specific question. Example: "How do I get the gird item that I want to transfer to the drop target". If you follow these guidelines in future posts you will likely get better a faster responses.

    That said, I did writer this code for you because I think it will benefit others as well:

            <GridView x:Name="_gf" IsItemClickEnabled="True" Background="Gray" HorizontalAlignment="Left" Margin="51,45,0,0" VerticalAlignment="Top" Width="297" Height="443" AllowDrop="True" CanReorderItems="True" CanDragItems="True" DragItemsStarting="_gf_DragItemsStarting" >
                <GridViewItem BorderBrush="Black" Content="This is a test"/>
                <GridViewItem BorderBrush="Black" Content="This is a test"/>
                <GridViewItem BorderBrush="Black" Content="This is a test"/>
                <GridViewItem BorderBrush="Black" Content="This is a test"/>
                <GridViewItem BorderBrush="Black" Content="This is a test"/>
                <GridViewItem BorderBrush="Black" Content="This is a test"/>
                <GridViewItem BorderBrush="Black" Content="This is a test"/>
            </GridView>
            <GridView x:Name="_gt" Background="black" HorizontalAlignment="Left" Margin="386,45,0,0" VerticalAlignment="Top" Width="297" Height="443" AllowDrop="True" CanDragItems="True" CanReorderItems="True" Drop="_gt_Drop"/>


    void DragAndDropCPP::MainPage::_gf_DragItemsStarting(Platform::Object^ sender, Windows::UI::Xaml::Controls::DragItemsStartingEventArgs^ e)
    {
    	e->Data->Properties->Insert("item", e->Items->GetAt(0));
    }
    void DragAndDropCPP::MainPage::_gt_Drop(Platform::Object^ sender, Windows::UI::Xaml::DragEventArgs^ e)
    {
    	_gt->Items->Append(e->Data->Properties->Lookup("item"));
    }

    I hope this helps,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Thursday, August 23, 2012 11:01 PM
    Moderator
  • hi james,

    thank you so much for your valuable reply . It works properly.

    Regards,
    Sarath s

    Friday, August 24, 2012 3:16 AM
  • hi james,

    is it possible to dragg an image from the gridview to a grid? if it is possible please provide me sample code.

    Regards,

    Sarath s


    Friday, August 24, 2012 8:11 AM
  • It might work. Did you try it? You should be able to use the same technique above. If you have any specific questions I will try to answer them for you.

    -James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Friday, August 24, 2012 10:46 PM
    Moderator
  • hi james,

    thanks . It works...

    Regards,

    Sarath s


    Monday, September 3, 2012 3:39 AM