RadDragAndDropManager and RadGridView

13 posts, 0 answers
  1. Allan
    Allan avatar
    24 posts
    Member since:
    Jun 2009

    Posted 15 Jul 2009 Link to this post

    Any examples of dragging a row from RadGridView onto another control using the RadDragAndDropManager?    
  2. Allan
    Allan avatar
    24 posts
    Member since:
    Jun 2009

    Posted 15 Jul 2009 Link to this post

    OK .. I downloaded the DragDropTest which is Silverlight and tried to apply the same principles to the WPF version. It doesn't seem to work as I would expect.

    Here is what I'm trying to do ... drag a row from a RadGridView onto a TextBlock that will then fire a command to add the data to another view. I know the drop on the TextBlock is working, as I can drag a file from windows explorer onto it and it fires.

    I've had to change some of the control names, etc, for legalese .. so forgive me if this does not work right off the bat.


     

     

     

     

    <

    UserControl x:Class="UserControls.MyControl"

     

     

     

     

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

     

     

     

     

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

     

     

     

     

    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"

     

     

     

     

    xmlns:GridView="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView"

     

     

    xmlns:dragDrop="clr-namespace:Telerik.Windows.Controls.DragDrop;assembly=Telerik.Windows.Controls"

     

     

     

     

    Height="Auto" Width="Auto">

     

     

     

     

     

    <Grid Name="LayoutRoot">

     

     

     

     

    <Grid.RowDefinitions>

     

     

     

     

    <RowDefinition Height="Auto"></RowDefinition>

     

     

     

     

    <RowDefinition Height="*"></RowDefinition>

     

     

     

     

    </Grid.RowDefinitions>

     

     

     

     


     

     

     

     

    <TextBox Name="dropTextBox"

     

     

    Text="Drop a row here to add ..."

     

     

    AllowDrop="True"

     

     

    Grid.Row="0"

     

     

    PreviewDragEnter="OnDragOver"

     

     

     

     

    PreviewDragOver="OnDragOver"/>

     

     

     

     

    <RadGridView ScrollViewer.CanContentScroll="True"

     

     

    ScrollMode="RealTime"

     

     

     

     

    IsFilteringAllowed="True"

     

     

    DataLoadMode="Asynchronous"

     

     

    ColumnsWidthMode="Fill"

     

     

    Width="Auto"

     

     

    Height="Auto"

     

     

    Name="dataGrid"

     

     

    VerticalAlignment="Top"

     

     

    HorizontalAlignment="Center"

     

     

     

     

    ItemsSource="{Binding SearchList}"

     

     

     

     

    AllowDrop="False"

     

     

     

     

    Grid.Row="1">

     

     

     

     

    <RadGridView.RowAppearance>

     

     

     

     

    <telerik:RowAppearanceSettings>

     

     

     

     

    <telerik:RowAppearanceSettings.RowStyle>

     

     

     

     

    <Style TargetType="GridView:GridViewRow">

     

     

     

     

    <Setter Property="dragDrop:RadDragAndDropManager.AllowDrag" Value="True" />

     

     

     

     

    </Style>

     

     

     

     

    </telerik:RowAppearanceSettings.RowStyle>

     

     

     

     

    <telerik:RowAppearanceSettings.AlternateRowStyle>

     

     

     

     

    <Style TargetType="GridView:GridViewRow">

     

     

     

     

    <Setter Property="dragDrop:RadDragAndDropManager.AllowDrag" Value="True" />

     

     

     

     

    </Style>

     

     

     

     

    </telerik:RowAppearanceSettings.AlternateRowStyle>

     

     

     

     

    </telerik:RowAppearanceSettings>

     

     

     

     

    </RadGridView.RowAppearance>

     

     

     

     

    </RadGridView>

     

     

     

     

    </Grid>

     

     

     

     

     

     

    </

    UserControl>

     

     

    public

    partial class MyControl: UserControl

     

    {

     

    public static RoutedCommand OnDropCommand = new RoutedCommand();

     

     

    public MyControl()

     

    {

    InitializeComponent();

     

    RadDragAndDropManager.SetAllowDrop(dropTextBox, true);

     

    dropTextBox.Drop +=

    new DragEventHandler(dropTextBox_Drop);

     

    dataGrid.DragQuery +=

    new EventHandler<DragDropQueryEventArgs>(OnDragQuery);

     

    dataGrid.DragInfo +=

    new EventHandler<DragDropEventArgs>(OnDragInfo);

     

    }

     

    void dropTextBox_Drop(object sender, DragEventArgs e)

     

    {

    OnDropCommand.Execute(e.Data,

    null);

     

    }

     

    private void OnDragOver(object sender, DragEventArgs e)

     

    {

    e.Effects =

    DragDropEffects.All;

     

    e.Handled =

    true;

     

    }

     

    void OnDragInfo(object sender, DragDropEventArgs e)

     

    {

     

    if (e.Options.Status == DragStatus.DragComplete)

     

    {

    e.Handled =

    true;

     

    }

    }

     

    protected virtual void OnDragQuery(object sender, DragDropQueryEventArgs e)

     

    {

    e.QueryResult =

    true;

     

     

    if (e.Options.Status == DragStatus.DragQuery)

     

    {

     

    List<object> items = new List<object>();

     

     

    string cueText = string.Empty;

     

     

    foreach (var item in dataGrid.SelectedRecords)

     

    {

    items.Add(item);

    }

    e.Options.Payload = items;

     

    ContentControl cue = new ContentControl();

     

    cue.Content =

    "Dragging ...";

     

    e.Options.DragCue = cue;

    e.Options.Destination = dropTextBox;

    }

    }

     

     

     

     

    }

     

     

     

     

  3. UI for WPF is Visual Studio 2017 Ready
  4. Allan
    Allan avatar
    24 posts
    Member since:
    Jun 2009

    Posted 15 Jul 2009 Link to this post

    One other thing .. if I enable dropping onto the RadGridView, I can get that to fire ... it seems like I'm missing whatever it is to allow the row to be dropped outside of the RadGridView.
  5. Allan
    Allan avatar
    24 posts
    Member since:
    Jun 2009

    Posted 15 Jul 2009 Link to this post

    I changed the OnDragInfo as follows, and set breakpoints on each option. When the row is dropped onto the TextBox, the option is DragStatus.Cancel - why would that be?


     

    void OnDragInfo(object sender, DragDropEventArgs e)

     

    {

     

    switch (e.Options.Status)

     

    {

     

    case DragStatus.DragCancel:

     

    {

    e.Handled =

    true;

     

     

    break;

     

    }

     

    case DragStatus.DragInProgress:

     

    {

    e.Handled =

    true;

     

     

    break;

     

    }

     

    case DragStatus.DragComplete:

     

    {

    e.Handled =

    true;

     

     

    break;

     

    }

     

    case DragStatus.DragQuery:

     

    {

    e.Handled =

    true;

     

     

    break;

     

    }

     

    case DragStatus.DropCancel:

     

    {

    e.Handled =

    true;

     

     

    break;

     

    }

     

    case DragStatus.DropComplete:

     

    {

    e.Handled =

    true;

     

     

    break;

     

    }

     

    case DragStatus.DropDestinationQuery:

     

    {

    e.Handled =

    true;

     

     

    break;

     

    }

     

    case DragStatus.DropImpossible:

     

    {

    e.Handled =

    true;

     

     

    break;

     

    }

     

    case DragStatus.DropPossible:

     

    {

    e.Handled =

    true;

     

     

    break;

     

    }

     

    case DragStatus.DropSourceQuery:

     

    {

    e.Handled =

    true;

     

     

    break;

     

    }

     

    case DragStatus.None:

     

    {

    e.Handled =

    true;

     

     

    break;

     

    }

    }

    }

  6. Allan
    Allan avatar
    24 posts
    Member since:
    Jun 2009

    Posted 16 Jul 2009 Link to this post

    I submitted a support ticket with a example project, ticket ID 227877
  7. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 17 Jul 2009 Link to this post

    Hello Allan,

    I am sorry forthe delayed reply!

    Today I replied to your ticket and I am copying my answer here as well:

    =========

    Unfortunately most of the examples for the DragDrop are in Silvertlight because the DragAndDropManager was ported from Silverlight to WPF, mostly for code compatibility. Therefore you should be able to reuse almost all of the examples that are for Silverlight (though we will be converting them as well).

    Thank you for sending us the sample project!

    There are several things that I noticed:
    1. You are inheriting the GridView. In the online examples we are also doing so with the ListBox but this is just to show how you can expose the DragDrop events as standard CLR events.
    2. You are handling the standard DragDrop events for the text block, while the RadDragDropmanager has separate events that need to be handled. We are not raising the default events (and I am not sure that we could).
    3. In the DragQuery handler you are setting the destination of the DragDrop. The destination is determined by the user dragging with the mouse and cannot be chosen by you. In code the effect of the DragDrop can affect any object, but the destination is there to tell you where is the user dragging.

    Hopefully this will get you started with the DragDrop.

    Greetings,
    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  8. StevenDale
    StevenDale avatar
    100 posts
    Member since:
    Apr 2007

    Posted 14 Oct 2009 Link to this post

    Could you possibly supply a small example of how to do the drag / drop from one RadGridView to another RadGridView?

    Thanks,

    Billy Jacobs
  9. Roger Andersson
    Roger Andersson avatar
    15 posts
    Member since:
    Jul 2009

    Posted 15 Oct 2009 Link to this post

    I agree, would also like an example.
    I've been trying to get this to work...
    but no luck
  10. StevenDale
    StevenDale avatar
    100 posts
    Member since:
    Apr 2007

    Posted 15 Oct 2009 Link to this post

    I found an example of Drag and Drop from one RadGridView to another that works well unless there is any reason you need to use you left mouse button on the Grid such as to edit within a column or have a child heirarchy.

    The example is here : http://www.telerik.com/clientsfiles/131120_rowdragdrop.zip

    Good Luck,

    Billy Jacobs
  11. Roger Andersson
    Roger Andersson avatar
    15 posts
    Member since:
    Jul 2009

    Posted 15 Oct 2009 Link to this post

    Thanks, I just tried that and it works, I also tried to use some the principle of it for my GridView <=> TreeView DragnDrop feature
    but was unable to create it.

    This 'GridViewDragDrop' can only work with two GridView's and I'm looking for some example when handling a GridView with other controls, like in my example a TreeView.

    got one of those?

    //TIA RA


    ( Related Link: http://www.telerik.com/community/forums/winforms/gridview/drag-and-drop.aspx#969719 )
  12. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 20 Oct 2009 Link to this post

    Hello Roger Andersson,

    Please check this example.
    http://demos.telerik.com/silverlight/#DragAndDrop/TreeToGrid

    You can also download the BugTracker example from your telerik account to see examples of drag and drop between different controls.

    Regards,
    Valentin.Stoychev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  13. Roger Andersson
    Roger Andersson avatar
    15 posts
    Member since:
    Jul 2009

    Posted 20 Oct 2009 Link to this post

    Is this convertable to WFP? since it's SilverLight.

    I tried to get some code from this into our project but a lot of code for the 'TreeViewDragCue' won't work.
    eg. 'ItemTemplate', 'ItemsSource', 'IsDropPossible' etc
    These don't seem to exist under 'TreeViewDragCue'

    Using Telerik.Windows.Controls.dll of version: 2009.2.701.35
    No patches or such added as far as I know.
  14. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 23 Oct 2009 Link to this post

    Hello Roger,

    Yes, it is possible to convert the example for WPF, in fact you can view the same example in the WPF QSF as well:

    http://demos.telerik.com/wpf/

    Indeed, in the  2.701 version that you use TreeViewDragCue is different. The SP1 version (2.813) of the includes all the changes you need for the TreeViewDragCue. You can also get the example straight from the WPF QSF.

    Please note that in the SP version the WPF DragDrop has a bug where it does not work with editable TextBoxes (it crashes with null ref. exception). If you have this issue in your application, you may need to use any of the internal builds after 2.820. Alternatively, if you do not want to use non-official versions you can wait for the Q3 release which is expected soon.

    Greetings,
    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top
UI for WPF is Visual Studio 2017 Ready