This is a migrated thread and some comments may be shown as answers.

RadDragAndDropManager and RadGridView

12 Answers 453 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Allan
Top achievements
Rank 1
Allan asked on 15 Jul 2009, 04:51 PM
Any examples of dragging a row from RadGridView onto another control using the RadDragAndDropManager?    

12 Answers, 1 is accepted

Sort by
0
Allan
Top achievements
Rank 1
answered on 15 Jul 2009, 10:28 PM

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;

}

}

 

 

 

 

}

 

 

 

 

0
Allan
Top achievements
Rank 1
answered on 15 Jul 2009, 10:33 PM
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.
0
Allan
Top achievements
Rank 1
answered on 15 Jul 2009, 11:07 PM
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;

 

}

}

}

0
Allan
Top achievements
Rank 1
answered on 16 Jul 2009, 03:03 PM
I submitted a support ticket with a example project, ticket ID 227877
0
Miroslav
Telerik team
answered on 17 Jul 2009, 02:17 PM
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.
0
StevenDale
Top achievements
Rank 2
answered on 15 Oct 2009, 01:45 AM
Could you possibly supply a small example of how to do the drag / drop from one RadGridView to another RadGridView?

Thanks,

Billy Jacobs
0
Roger Andersson
Top achievements
Rank 1
answered on 15 Oct 2009, 11:04 AM
I agree, would also like an example.
I've been trying to get this to work...
but no luck
0
StevenDale
Top achievements
Rank 2
answered on 15 Oct 2009, 12:55 PM
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
0
Roger Andersson
Top achievements
Rank 1
answered on 15 Oct 2009, 01:04 PM
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 )
0
Valentin.Stoychev
Telerik team
answered on 20 Oct 2009, 09:19 AM
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.
0
Roger Andersson
Top achievements
Rank 1
answered on 20 Oct 2009, 02:24 PM
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.
0
Miroslav
Telerik team
answered on 23 Oct 2009, 12:41 PM
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.
Tags
GridView
Asked by
Allan
Top achievements
Rank 1
Answers by
Allan
Top achievements
Rank 1
Miroslav
Telerik team
StevenDale
Top achievements
Rank 2
Roger Andersson
Top achievements
Rank 1
Valentin.Stoychev
Telerik team
Share this question
or