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

Nested Drag and Drop

1 Answer 88 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Frustrated Dev
Top achievements
Rank 1
Frustrated Dev asked on 02 Apr 2010, 03:01 AM
Please Disregard. I figured it out. I was not casting the destination properly.

Hello,

I have an ItemsControl where each item is a TreeView. Below this ItemsControl is a GridView with a list of items. I'm trying to allow a user to drag items from the GridView into one of the TreeViews in the ItemsControl. When a user drops the item from the GridView onto a TreeView, the item would get added to that specific TreeView.  My XAML looks like the following:

<Grid> 
  <Grid.RowDefinitions> 
    <RowDefinition /> 
    <RowDefinition />  
  </Grid.RowDefinitions> 
 
  <Grid> 
    <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition /> 
    </Grid.RowDefinitions> 
 
    <StackPanel Orientation="Horizontal"
      <TextBlock Text="Tasks" VerticalAlignment="Center" /> 
    </StackPanel> 
 
    <ItemsControl x:Name="myItemsControl" Grid.Row="1"   
      telerikDragDrop:RadDragAndDropManager.AllowDrag="True"   
      Loaded="myItemsControl_Loaded"
      <ItemsControl.ItemTemplate> 
        <DataTemplate> 
          <navigation:RadTreeView x:Name="myTree" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" Loaded="myTree_Loaded"
            <navigation:RadTreeViewItem Header="{Binding}"
              <navigation:RadTreeViewItem.ItemTemplate> 
                <DataTemplate> 
                  <TextBlock Text="{Binding}" /> 
                </DataTemplate> 
              </navigation:RadTreeViewItem.ItemTemplate> 
            </navigation:RadTreeViewItem> 
          </navigation:RadTreeView> 
        </DataTemplate> 
      </ItemsControl.ItemTemplate> 
    </ItemsControl> 
  </Grid> 
 
  <Grid Grid.Row="1"
    <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition /> 
    </Grid.RowDefinitions> 
 
    <StackPanel Orientation="Horizontal"
      <TextBlock Text="Days" /> 
    </StackPanel> 
 
    <telerik:RadGridView x:Name="myGridView" UseAlternateRowStyle="True"  
      AutoGenerateColumns="False" ShowGroupPanel="False" Grid.Row="1"  
      telerikDragDrop:RadDragAndDropManager.AllowDrop="True"  
      Loaded="myGridView_Loaded"
      <telerik:RadGridView.RowStyle> 
        <Style TargetType="gridview:GridViewRow"
          <Setter Property="telerikDragDrop:RadDragAndDropManager.AllowDrag" Value="True" /> 
        </Style> 
       </telerik:RadGridView.RowStyle> 
     <telerik:RadGridView.Columns> 
     <telerik:GridViewDataColumn Header="Day" DataMemberBinding="{Binding}" IsReadOnly="True" IsFilterable="False" IsGroupable="False"  /> 
   </telerik:RadGridView.Columns> 
 </telerik:RadGridView> 
 </Grid> 
 </Grid> 
 


I can drag items from the GridView. But I cannot identify how to drop it on one of the TreeViews in the ItemsControl.  I have a message box that should say "dropped". But it is not triggering. I'm not sure what I'm doing wrong. My C# code is provided below. What am I doing wrong? How can I accomplish this?

Thank you for your help,

private void myTree_Loaded(object sender, RoutedEventArgs e) 
  RadTreeView myTreeView = (RadTreeView)(sender); 
  RadDragAndDropManager.SetAllowDrop(myTreeView, true); 
 
  RadDragAndDropManager.AddDropQueryHandler(myTreeView, myTreeView_OnDropQuery); 
  RadDragAndDropManager.AddDropInfoHandler(myTreeView, myTreeView_OnDropInfo); 
 
private void myTreeView_OnDropQuery(object sender, Telerik.Windows.Controls.DragDrop.DragDropQueryEventArgs e) 
  RadGridView destination = sender as RadGridView; 
  if (destination != null
  { 
    e.Handled = true
    e.QueryResult = true
  } 
 
private void myTreeView_OnDropInfo(object sender, Telerik.Windows.Controls.DragDrop.DragDropEventArgs e) 
  RadGridView destination = sender as RadGridView; 
  if (e.Options.Status == Telerik.Windows.Controls.DragDrop.DragStatus.DropComplete) 
  { 
    MessageBox.Show("dropped!"); 
  } 
 
private void myItemsControl_Loaded(object sender, RoutedEventArgs e) 
  List<string> tasks = new List<string>(); 
  tasks.Add("Sweep Floor"); 
  tasks.Add("Task out Garbage"); 
  tasks.Add("Clean Windows"); 
   
  myItemsControl.ItemsSource = tasks; 
 
private void myGridView_Loaded(object sender, RoutedEventArgs e) 
  RadDragAndDropManager.AddDropQueryHandler(myGridView, myGridView_OnDropQuery); 
  RadDragAndDropManager.AddDropInfoHandler(myGridView, myGridView_OnDropInfo); 
  RadDragAndDropManager.AddDragQueryHandler(myGridView, myGridView_OnDragQuery); 
  RadDragAndDropManager.AddDragInfoHandler(myGridView, myGridView_OnDragInfo); 
 
  List<string> days = new List<string>(); 
  days.Add("Sunday"); 
  days.Add("Monday"); 
  days.Add("Tuesday"); 
  days.Add("Wednesday"); 
  days.Add("Thursday"); 
  days.Add("Friday"); 
  days.Add("Saturday"); 
  myGridView.ItemsSource = days; 
 
private void myGridView_OnDragQuery(object sender, DragDropQueryEventArgs e) 
  RadGridView gridView = sender as RadGridView; 
  if (gridView != null
    e.Options.Payload = gridView.SelectedItem; 
 
   // Inform the event handlers that we have programmatically handled it 
   e.QueryResult = true
   e.Handled = true
 
private void myGridView_OnDragInfo(object sender, DragDropEventArgs e) 
  RadGridView gridView = sender as RadGridView; 
  string draggedItem = e.Options.Payload as string
 
  if (e.Options.Status == DragStatus.DragInProgress) 
  { 
    //Setting up a drag cue: 
    ContentControl cue = new ContentControl(); 
    //Choosing a template for the items: 
    cue.ContentTemplate = this.Resources["MyTemplate"as DataTemplate; 
    cue.Content = draggedItem; 
    e.Options.DragCue = cue; 
  } 
  else if (e.Options.Status == DragStatus.DragComplete) 
  { 
    //deleting the dragged item from the RadGridView 
    //                IList source = gridView.ItemsSource as IList; 
    //                source.Remove(draggedItem); 
  } 
 
private void myGridView_OnDropQuery(object sender, Telerik.Windows.Controls.DragDrop.DragDropQueryEventArgs e) 
  RadGridView destination = sender as RadGridView; 
  if (destination != null
  { 
    e.Handled = true
    e.QueryResult = true
  } 
 
private void myGridView_OnDropInfo(object sender, Telerik.Windows.Controls.DragDrop.DragDropEventArgs e) 
  RadGridView destination = sender as RadGridView; 
  if (e.Options.Status == Telerik.Windows.Controls.DragDrop.DragStatus.DropComplete) 
   { 
   } 

1 Answer, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 02 Apr 2010, 03:36 PM
Hello Frustrated Dev,

We are glad to hear that.

Please let us know if you need more info.

All the best,
Tina Stancheva
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
DragAndDrop
Asked by
Frustrated Dev
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question
or