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

Drop is not working on a Drag&Drop within GridViews

3 Answers 114 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Victor
Top achievements
Rank 1
Victor asked on 18 Nov 2010, 06:09 PM
Hi,

I'm trying to do a Drag&Drop between 2 differents RadGridViews.
The DragEvent is working properly, but the DropEvent is never triggered.
I'm provably missing something, but I've been reading threads and I couldn't find the problem.
Hope u guys can help me. Thanks in advance.

My code-behind:
public PermisosListView()
     {
         InitializeComponent();
 
         RadDragAndDropManager.AddDropQueryHandler(PermisosTots, RadGridView_OnDropQuery);
         RadDragAndDropManager.AddDropInfoHandler(PermisosTots, RadGridView_OnDropInfo);
         RadDragAndDropManager.AddDragQueryHandler(PermisosTots, OnGridViewDragQuery);
         RadDragAndDropManager.AddDragInfoHandler(PermisosTots, OnGridViewDragInfo);
 
         RadDragAndDropManager.AddDropQueryHandler(PermisosAsignats, RadGridView_OnDropQuery2);
         RadDragAndDropManager.AddDropInfoHandler(PermisosAsignats, RadGridView_OnDropInfo2);
         RadDragAndDropManager.AddDragQueryHandler(PermisosAsignats, OnGridViewDragQuery2);
         RadDragAndDropManager.AddDragInfoHandler(PermisosAsignats, OnGridViewDragInfo2);
     }
 
     #region DragDropEvent handlers 1
 
     //DragQuery event handler
     private void OnGridViewDragQuery(object sender, DragDropQueryEventArgs e)
     {
         RadGridView gridView = sender as RadGridView;
         //PermisosListView gridView = (PermisosListView)sender;
         if (gridView != null)
         {
             e.Options.Payload = gridView.SelectedItem;
             //e.Options.Payload = gridView.PermisosTots.CurrentItem;
         }
         e.QueryResult = true;
         e.Handled = true;
         e.Options.ArrowCue = RadDragAndDropManager.GenerateArrowCue();
         Permisos p = (Permisos)gridView.SelectedItem;
        // MessageBox.Show(p.Permis);
     }
 
     //DragInfo event handler
     private void OnGridViewDragInfo(object sender, DragDropEventArgs e)
     {
         RadGridView gridView = sender as RadGridView;
         var draggedItem = e.Options.Payload;
 
         if (e.Options.Status == DragStatus.DragInProgress && draggedItem != null)
         {
             //Setting up a drag cue:
             ContentControl cue = new ContentControl();
             //Choosing a template for the items:
             //cue.ContentTemplate = this.Resources["ProductTemplate"] as DataTemplate;
              
             Permisos p = (Permisos)draggedItem;
             cue.Content = p.Permis;
             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);
         }
     }
 
     //DropQuery event handler
     private void RadGridView_OnDropQuery(object sender, DragDropQueryEventArgs e)
     {
         var destination = sender as RadGridView;
 
         if (destination != null)
         {
             e.Handled = true;
             e.QueryResult = true;
         }
     }
 
     //DropInfo event handler
     private void RadGridView_OnDropInfo(object sender, DragDropEventArgs e)
     {
         RadGridView destination = sender as RadGridView;
 
         if (e.Options.Status == DragStatus.DropComplete)
         {
             GridViewCell destCell = e.Options.Destination as GridViewCell;
             if (destCell != null)
             {
                 var ID = destCell.Column.Header;
             }
             //(destination.ItemsSource as IList<ProductViewModel>).Add(e.Options.Payload as ProductViewModel);
         }
     }
 
     #endregion

Same code for the other GridView.
...Drop event are never triggered.

My xaml:
<Control.Resources>
      <Style TargetType="ListBoxItem" x:Key="draggableItemStyle">
          <Setter Property="HorizontalAlignment" Value="Stretch" />
          <Setter Property="HorizontalContentAlignment" Value="Stretch" />
          <Setter Property="Foreground" Value="#000000" />
          <Setter Property="telerik:RadDragAndDropManager.AllowDrag" Value="True" />
          <Setter Property="telerik:RadDragAndDropManager.AllowDrop" Value="True" />
      </Style>
  </Control.Resources>
   
  <Grid>
      <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*"/>
          <ColumnDefinition Width="30"/>
          <ColumnDefinition Width="*"/>
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="*"/>
          <RowDefinition Height="Auto"/>
      </Grid.RowDefinitions>
 
       
      <sdk:Label Content="Permisos Asignats" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Center" FontWeight="Bold" />
      <sdk:Label Content="Tots els permisos" Grid.Column="2" Grid.Row="0" HorizontalAlignment="Center" FontWeight="Bold" />
 
      <Controls1:RadButton Command="{Binding AddPermisoCommand}"  Height="30" Width="30" Grid.Column="1" Grid.Row="1" Margin="0,78,0,148" Content="<" FontWeight="Bold" />
      <Controls1:RadButton Command="{Binding RemovePermisoCommand}"  Height="30" Width="30" Grid.Column="1" Grid.Row="1" Margin="0,149,0,77" Content=">" FontWeight="Bold" />
 
      <telerikQuickStart:HeaderedContentControl Header="Permisos Asignats" Name="Asignats"
              HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
              Grid.Column="0" Grid.Row="1" Drop="Asignats_Drop">
 
           
          <Controls2:RadGridView x:Name="PermisosAsignats" ItemsSource="{Binding CurrentGrup.Permisos}"   Grid.Row="1" Grid.Column="0"
                           SelectedItem="{Binding Mode=TwoWay, BindsDirectlyToSource=True,
                           Path=CurrentPermis, ValidatesOnNotifyDataErrors=False}"
                           RowIndicatorVisibility="Collapsed"
                           telerik:RadDragAndDropManager.AllowDrop="True"
                           telerik:RadDragAndDropManager.AllowDrag="True"
                           ItemContainerStyle="{StaticResource draggableItemStyle}"
                           AutoGenerateColumns="False" VerticalAlignment="Stretch"         
                           CanUserFreezeColumns="True" BorderThickness="0" CanUserResizeColumns="False"
                           ShowGroupPanel="True" Margin="0,0,0,1" Width="Auto" ShowGroupFooters="True"
                           ShowInsertRow="False" ShowColumnFooters="False"
                           AlternateRowBackground="#FFF9F193" AlternationCount="2" IsReadOnly="True" IsFilteringAllowed="True" CanUserDeleteRows="False" CanUserInsertRows="False"
                           AllowDrop="True" Drop="PermisosAsignats_Drop">
 
              <Controls2:RadGridView.Columns>
                  <Controls2:GridViewDataColumn DataMemberBinding="{Binding Permis}" IsResizable="True" Header="Permis" />
                  <!--<Controls2:GridViewDataColumn DataMemberBinding="{Binding Command}" IsResizable="True" Header="Command" />-->
              </Controls2:RadGridView.Columns>
 
              <Controls2:RadGridView.GroupDescriptors>
                  <data:GroupDescriptor Member="AgrupacioPermisos.Descripcio" DisplayContent="Grupo de permisos" />
              </Controls2:RadGridView.GroupDescriptors>
 
              <i:Interaction.Triggers>
                  <!--<i:EventTrigger EventName="Drop" >
                  <ei:CallMethodAction MethodName="Drop" TargetObject="{Binding ElementName=PermisosAsignats, Path=DataContext}" />
                  </i:EventTrigger>-->
              </i:Interaction.Triggers>
          </Controls2:RadGridView>
      </telerikQuickStart:HeaderedContentControl>
       
      <Controls:RadDataPager Grid.Row="2" Grid.Column="0"
                             PageSize="{Binding PagerPageSize, Mode=TwoWay}"
                             Source="{Binding Items, ElementName=PermisosAsignats}"
                             DisplayMode="All"
                             AutoEllipsisMode="Both"
                             NumericButtonCount="10"
                             IsTotalItemCountFixed="True"
                             />
      <telerikQuickStart:HeaderedContentControl Header="Tots els permisos" Name="Tots"
              HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
              Grid.Column="2" Grid.Row="1" Drop="Tots_Drop">
          <Controls2:RadGridView x:Name="PermisosTots" ItemsSource="{Binding PermisosNoAsignats}"   Grid.Row="1" Grid.Column="2"
                           SelectedItem="{Binding Mode=TwoWay, BindsDirectlyToSource=True,
                           Path=CurrentItem, ValidatesOnNotifyDataErrors=False}"
                           RowIndicatorVisibility="Collapsed"
                           telerik:RadDragAndDropManager.AllowDrop="True"
                           telerik:RadDragAndDropManager.AllowDrag="True"
                            
                           AutoGenerateColumns="False" VerticalAlignment="Stretch"         
                           CanUserFreezeColumns="True" BorderThickness="0" CanUserResizeColumns="False"
                           ShowGroupPanel="True" Margin="0,0,0,1" Width="Auto" ShowGroupFooters="True"
                           ShowInsertRow="False" ShowColumnFooters="False"
                           AlternateRowBackground="#FFF9F193" AlternationCount="2" IsReadOnly="True" IsFilteringAllowed="True" CanUserDeleteRows="False" CanUserInsertRows="False"
                           AutoExpandGroups="True" AllowDrop="True" Drop="PermisosTots_Drop">
 
              <Controls2:RadGridView.Columns>
                  <Controls2:GridViewDataColumn DataMemberBinding="{Binding Permis}" IsResizable="True" Header="Permis" />
              </Controls2:RadGridView.Columns>
 
              <Controls2:RadGridView.GroupDescriptors>
                  <data:GroupDescriptor Member="AgrupacioPermisos.Descripcio" DisplayContent="Grupo de permisos" />
              </Controls2:RadGridView.GroupDescriptors>
 
              <i:Interaction.Triggers>
                  <i:EventTrigger EventName="RowActivated" >
                      <ei:CallMethodAction MethodName="Sel" TargetObject="{Binding ElementName=PermisosTots, Path=DataContext}" />
                  </i:EventTrigger>
 
                  <i:EventTrigger EventName="Filtered" >
                  <i:InvokeCommandAction Command="{Binding FilterCommand}" CommandParameter="{Binding ElementName=PermisosTots, Path=FilterDescriptors}" />
                  </i:EventTrigger>
 
                  <!--<i:EventTrigger EventName="Drop" >
                      <i:InvokeCommandAction Command="{Binding DropCommand}" CommandParameter="{Binding ElementName=PermisosTots, Path=FilterDescriptors}" />
                  </i:EventTrigger>-->
              </i:Interaction.Triggers>
          </Controls2:RadGridView>
       
      </telerikQuickStart:HeaderedContentControl>
      <Controls:RadDataPager Grid.Row="2" Grid.Column="2"
                             PageSize="{Binding PagerPageSize, Mode=TwoWay}"
                             Source="{Binding Items, ElementName=PermisosTots}"
                             DisplayMode="All"
                             AutoEllipsisMode="Both"
                             NumericButtonCount="10"
                             IsTotalItemCountFixed="True"
                             PageIndex="{Binding CurrentPage, Mode=TwoWay}"/>



I've commented the <i:EventTrigger EventName="Drop" > to try the Drop event using the codebehind and not using the ViewModel.

Thanks once again!

3 Answers, 1 is accepted

Sort by
0
Tsvyatko
Telerik team
answered on 24 Nov 2010, 09:32 AM
Hi Victor,

From the information shared I assume you are reffering to Drop event of the framework element. However, RadDragAndDropManager does not work with this event since it is present in SL to handle dropping from external programs. Instead RadDragAndDropManager offers 4 event to handle and control drag/drop operations. The Drop event will be equvalent to DropInfo when status is DropComplete.

Let me know if you have any further questions.

Greetings,
Tsvyatko
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Victor
Top achievements
Rank 1
answered on 24 Nov 2010, 10:47 AM
I'm using the RadDragAndDropManager events: DragQuery, DragInfo, DropQuery and DropInfo.
None of the Drop events are triggered when I drag and drop an element from another RadGridView.
0
Maya
Telerik team
answered on 26 Nov 2010, 01:02 PM
Hi Victor,

I am sending you a sample project reproducing your scenario. Please take a look at it and let me know if there are some misunderstandings according to your requirements or something that you need any further help on.
 

All the best,
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
DragAndDrop
Asked by
Victor
Top achievements
Rank 1
Answers by
Tsvyatko
Telerik team
Victor
Top achievements
Rank 1
Maya
Telerik team
Share this question
or