12 Answers, 1 is accepted
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;
}
}
}
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;
}
}
}
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.
Thanks,
Billy Jacobs
I've been trying to get this to work...
but no luck
The example is here : http://www.telerik.com/clientsfiles/131120_rowdragdrop.zip
Good Luck,
Billy Jacobs
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 )
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.
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.
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.