DragStatus always Impossible

2 posts, 0 answers
  1. Mark
    Mark avatar
    155 posts
    Member since:
    Oct 2010

    Posted 28 Apr 2011 Link to this post

    Two RadGridViews on a modal window.  Trying to drag between them.  Set both grids to allowdrag and allowdrop in XAML to true.  At no time can I drop on the grid.  The DragStatus never changes to Possible.  At the moment I'm just trying from the upper grid to lower and haven't implemented any business logic to handle the event.  I'm just trying to get it to fire.

    <controls:ChildWindow xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"   
        x:Class="RoasterWerks.Views.SaleModal"
        xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
        xmlns:ac="clr-namespace:RoasterWerks.Controls"
        xmlns:ex="clr-namespace:ComboBoxExtensions;assembly=ComboBoxExtensions"
        xmlns:s="clr-namespace:FirstLook.ServiceModel.DomainServices.Client.Security;assembly=FirstLook.ServiceModel.DomainServices.Client.Security"
        Width="925" Height="600" 
        Title="{Binding Path=ApplicationStrings.SaleModalTitle, Source={StaticResource ResourceWrapper}}"
        HasCloseButton="False" 
        s:Authorization.RequiresAuthentication="True" 
        mc:Ignorable="d" 
        xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices" 
        xmlns:my="clr-namespace:RoasterWerks.Web.Services" 
        xmlns:datatemplates="clr-namespace:RoasterWerks.DataTemplates" xmlns:my1="clr-namespace:RoasterWerks.Web.Models"
        xmlns:telerikDragDrop="clr-namespace:Telerik.Windows.Controls.DragDrop;assembly=Telerik.Windows.Controls">
      
        <sdk:ChildWindow.Resources>
      
            <LinearGradientBrush x:Key="DropPossibleBackground" StartPoint="0 0" EndPoint="0 1">
                <GradientStop Offset="0" Color="White" />
                <GradientStop Offset="1" Color="#FFE699" />
            </LinearGradientBrush>
      
            <SolidColorBrush x:Key="GridBackground" Color="#FFA4A6A9"/>
              
            <DataTemplate x:Key="SOItemDetailTemplate" >
                <datatemplates:SOItemDetailTemplate />
            </DataTemplate>
      
            <DataTemplate x:Key="InvItemTemplate">
                <datatemplates:InvItemTemplate />
            </DataTemplate>
              
        </sdk:ChildWindow.Resources>
      
      
            <Grid x:Name="LayoutRoot" Margin="2">
            <Grid.RowDefinitions>
                <RowDefinition Height="60*"/>
                <RowDefinition Height="20"/>
                <RowDefinition Height="40*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
      
            <toolkit:Accordion x:Name="acc_curInv" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                               HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
                <toolkit:AccordionItem Header="Current Inventory">
                    <toolkit:AccordionItem.Content>
                        <telerik:RadGridView  x:Name="dg_tblInv" 
                                         telerik:StyleManager.Theme="Expression_Dark" 
                                         ItemsSource="{Binding Path=Data, Mode=OneWay, ElementName=InventoryDDS}" 
                                         IsEnabled="True" IsReadOnly="True" ShowGroupPanel="True" 
                                         AutoGenerateColumns="False"  CanUserDeleteRows="False" 
                                         CanUserInsertRows="False" ShowInsertRow="False" 
                                         CanUserFreezeColumns="False" CanUserReorderColumns="False" Background="#FFA4A6A9" 
                                         RowDetailsVisibilityMode="Collapsed" 
                                         RowDetailsTemplate="{Binding Source={StaticResource SOItemDetailTemplate}}" 
                                         telerikDragDrop:RadDragAndDropManager.AllowDrop="True" 
                                         telerikDragDrop:RadDragAndDropManager.AllowDrag="True">
                            <telerik:RadGridView.Columns>
                                <telerik:GridViewToggleRowDetailsColumn />
                                <telerik:GridViewDataColumn UniqueName="dc_quantity" DataMemberBinding="{Binding Path=quantity}" IsFilterable="False" IsGroupable="False" IsReorderable="False" />
                                <telerik:GridViewDataColumn UniqueName="dc_packDesc" DataMemberBinding="{Binding Path=packDesc}" IsFilterable="False" IsGroupable="False" IsReorderable="False" />
                                <telerik:GridViewDataColumn UniqueName="dc_species" DataMemberBinding="{Binding Path=speciesID}" />
                                <telerik:GridViewDataColumn UniqueName="dc_varietal" DataMemberBinding="{Binding Path=varietal}" />
                                <telerik:GridViewDataColumn UniqueName="dc_grade" DataMemberBinding="{Binding Path=gradeName}" />
                                <telerik:GridViewDataColumn UniqueName="dc_length" DataMemberBinding="{Binding Path=LengthName}" />
                                <telerik:GridViewDataColumn UniqueName="dc_density" DataMemberBinding="{Binding Path=DensityShort}" />
                                <telerik:GridViewDataColumn UniqueName="dc_screen" DataMemberBinding="{Binding Path=ScreenName}" />
                                <telerik:GridViewImageColumn UniqueName="dc_screen" Header="Decaf." DataMemberBinding="{Binding Path=isDecaf, Converter={StaticResource BoolToImageConverter}}" />
                                <telerik:GridViewExpressionColumn UniqueName="exp_Lbs" Header="Est. Lbs." DataFormatString="{}{0:0,0}" TextAlignment="Right" HeaderTextAlignment="Right" />
                            </telerik:RadGridView.Columns>
                        </telerik:RadGridView >
                    </toolkit:AccordionItem.Content>
                </toolkit:AccordionItem>
            </toolkit:Accordion>
      
            <toolkit:Accordion x:Name="acc_SOLineItems" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                               Grid.Row="2" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
                <toolkit:AccordionItem Header="Sales Order Items">
                    <toolkit:AccordionItem.Content>
                        <telerik:RadGridView x:Name="dg_tblSOLines" 
                                             telerik:StyleManager.Theme="Expression_Dark" Height="Auto" Width="Auto" ShowGroupPanel="False"
                                             AutoGenerateColumns="False" ShowInsertRow="False" Background="#FFA4A6A9" 
                                             telerikDragDrop:RadDragAndDropManager.AllowDrop="True" 
                                             telerikDragDrop:RadDragAndDropManager.AllowDrag="True">
                            <telerik:RadGridView.Columns>
                                <telerik:GridViewDataColumn UniqueName="dc_quantitySO" Header="Quantity"
                                                            DataMemberBinding="{Binding Path=quantity}" IsFilterable="False" IsGroupable="False" IsReorderable="False" />
                            </telerik:RadGridView.Columns>
                        </telerik:RadGridView>
                    </toolkit:AccordionItem.Content>
                </toolkit:AccordionItem>
            </toolkit:Accordion>
      
            <Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Width="75" Height="Auto" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="3" />
            <Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="Auto" HorizontalAlignment="Right" Margin="0,12,79,0" Grid.Row="3" />
            <riaControls:DomainDataSource AutoLoad="True" LoadedData="qryInventoryDomainDataSource_LoadedData" Name="InventoryDDS" 
                                          QueryName="GetQryInventories" >
                <riaControls:DomainDataSource.DomainContext>
                    <my:RoasterWerksDomainContext/>
                </riaControls:DomainDataSource.DomainContext>
            </riaControls:DomainDataSource>
      
        </Grid>
    </controls:ChildWindow>

    using System.Windows;
    using System.Windows.Controls;
    using RoasterWerks.Web.Models;
    using System.Linq.Expressions;
    using System;
    using System.ComponentModel;
    using System.Linq;
    using Telerik.Windows.Controls.DragDrop;
    using Telerik.Windows.Data;
    using Telerik.Windows.Controls;
    using Telerik.Windows.Controls.GridView;
    using System.Collections;
    using Telerik.Windows.Controls.TreeView;
    using System.Windows.Media;
      
      
    namespace RoasterWerks.Views
    {
      
      
      
      
        public partial class SaleModal : ChildWindow
        {
            //RoasterWerksDomainContext context = new RoasterWerksDomainContext();
      
        
      
              
      
            public SaleModal(object sender)
            {
                InitializeComponent();
      
                RadDragAndDropManager.AddDragQueryHandler(dg_tblInv, OnTblInvDragQuery);
                RadDragAndDropManager.AddDragQueryHandler(dg_tblSOLines, OnSOLineDragQuery);
                RadDragAndDropManager.AddDragInfoHandler(dg_tblInv, OnTblInvDragInfo);
                RadDragAndDropManager.AddDragInfoHandler(dg_tblSOLines, OnSOLineDragInfo);
                RadDragAndDropManager.AddDropQueryHandler(dg_tblInv, OnTblInvDropQuery);
                RadDragAndDropManager.AddDropQueryHandler(dg_tblSOLines, OnSOLineDropQuery);
                RadDragAndDropManager.AddDropInfoHandler(dg_tblInv, OnTblInvDropInfo);
                RadDragAndDropManager.AddDropInfoHandler(dg_tblSOLines, OnSOLineDropInfo);
      
      
                setGridUp();
      
                if (((Button)sender).Name == "btn_AddPOLine")
                {
                    //newSOLine = new tblSOLine();
      
                }
      
                  
      
            }
      
            private void OnTblInvDragQuery(object sender, DragDropQueryEventArgs e)
            {
                if (e.Options.ParticipatingVisualRoots.Contains(this) == false)
                    e.Options.ParticipatingVisualRoots.Add(this);
      
                if (e.Options.Source is GridViewHeaderCell || e.Options.Source is GridViewGroupPanelCell) return;
      
                RadGridView gridView = sender as RadGridView;
                if (gridView != null)
                {
                    IList selectedItems = gridView.SelectedItems.ToList();
                    e.QueryResult = selectedItems.Count > 0;
                    e.Options.Payload = selectedItems;
                }
      
                e.QueryResult = true;
                e.Handled = true;
            }
      
            private void OnTblInvDragInfo(object sender, DragDropEventArgs e)
            {
                if (e.Options.Source is GridViewHeaderCell || e.Options.Source is GridViewGroupPanelCell) return;
      
                IEnumerable draggedItems = e.Options.Payload as IEnumerable;
      
                if (e.Options.Status == DragStatus.DragInProgress)
                {
                    //Set up drag cue
                    TreeViewDragCue cue = new TreeViewDragCue();
      
                    cue.ItemTemplate = this.Resources["InvItemTemplate"] as DataTemplate;
                    cue.ItemsSource = draggedItems;
                    cue.DragActionContent = "Drag Me To Sales Order Below.";
                    e.Options.DragCue = cue;
                }
                else if (e.Options.Status == DragStatus.DragComplete)
                {
                    /////////////////////////////////////////
                    //
                    // HERE WE MANAGE QUANTITY CHANGE IN QUANTITY BIZ LOGIC LATER
                    //
                    /////////////////////////////////////////
                    IList source = this.dg_tblInv.ItemsSource as IList;
                    foreach (object draggedItem in draggedItems)
                    {
                        source.Remove(draggedItem);
                    }
                }
            }
      
      
            private void OnSOLineDragQuery(object sender, DragDropQueryEventArgs e)
            {
                if (e.Options.ParticipatingVisualRoots.Contains(this) == false)
                    e.Options.ParticipatingVisualRoots.Add(this);
            }
      
            private void OnTblInvDropQuery(object sender, DragDropQueryEventArgs e)
            {
      
            }
      
            private void OnSOLineDropQuery(object sender, DragDropQueryEventArgs e)
            {
      
            }
      
              
      
            private void OnSOLineDragInfo(object sender, DragDropEventArgs e)
            {
      
            }
      
            private void OnTblInvDropInfo(object sender, DragDropEventArgs e)
            {
      
            }
      
            private void OnSOLineDropInfo(object sender, DragDropEventArgs e)
            {
                if (e.Options.Source is GridViewHeaderCell || e.Options.Source is GridViewGroupPanelCell) return;
      
                RadGridView order = e.Options.Destination as RadGridView;
                IEnumerable draggedItems = e.Options.Payload as IEnumerable;
      
                TreeViewDragCue cue = e.Options.DragCue as TreeViewDragCue;
      
                if (e.Options.Status == DragStatus.DropPossible)
                {
                    cue.DragActionContent = "Add item to Sales Order.";
                    cue.IsDropPossible = true;
                    order.Background = this.Resources["DropPossibleBackground"] as Brush;
                }
                else if (e.Options.Status == DragStatus.DropImpossible)
                {
                    cue.DragActionContent = null;
                    cue.IsDropPossible = false;
                }
                else if (e.Options.Status == DragStatus.DropComplete)
                {
                    IList items =order.ItemsSource as IList;
                    foreach (object draggedItem in draggedItems)
                    {
                        items.Add(draggedItem);
                    }
                }
                if (e.Options.Status != DragStatus.DropPossible)
                {
      
                    order.Background = this.Resources["GridBackground"] as Brush;
                }
      
            }
      
            private void setGridUp()
            {
                Expression<Func<qryInventory, decimal?>> expression = poLine => poLine.quantity * poLine.convPounds;
                GridViewExpressionColumn column = dg_tblInv.Columns["exp_Lbs"] as GridViewExpressionColumn;
                column.Expression = expression;
      
                //Group the grid by Origin
      
                Telerik.Windows.Data.GroupDescriptor desc = new Telerik.Windows.Data.GroupDescriptor();
                desc.Member = "origin";
                desc.SortDirection = ListSortDirection.Ascending;
                desc.DisplayContent = "Origin";
      
                AggregateFunction<qryInventory, decimal?> aggSumFunc = new AggregateFunction<qryInventory, decimal?>();
                //aggSumFunc.AggregationExpression = soLines => soLines.Sum(soLine => Math.Round((decimal)(soLine.quantity * soLine.convPounds)), 0));
                aggSumFunc.AggregationExpression = soLines => soLines.Sum(e => Math.Round((decimal)(e.quantity * e.convPounds),0));
                aggSumFunc.Caption = "Lbs Σ: ";
                aggSumFunc.ResultFormatString = "{0:N0}";
      
                desc.AggregateFunctions.Add(aggSumFunc);
                  
                dg_tblInv.GroupDescriptors.Add(desc);
      
            }
      
            private void OKButton_Click(object sender, RoutedEventArgs e)
            {
                this.DialogResult = true;
            }
      
            private void CancelButton_Click(object sender, RoutedEventArgs e)
            {
                this.DialogResult = false;
            }
      
            public tblSOLine newSOLine { get; set; }
      
            private void qryInventoryDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
            {
      
                if (e.HasError)
                {
                    System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                    e.MarkErrorAsHandled();
                }
                 
            }
      
            private void tblPOLineDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
            {
      
                if (e.HasError)
                {
                    System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                    e.MarkErrorAsHandled();
                }
            }
      
            private void tblPOLineDds_LoadedData(object sender, LoadedDataEventArgs e)
            {
      
            }
      
      
      
      
      
              
        }
    }

    The ItemsSource of the 2nd grid is being set from the Parent page:
    SaleModal saleModal = new SaleModal(btn_AddSOLine);
      
                //pass current tblSOLedger.tblSOLine to modal datagrid
                saleModal.dg_tblSOLines.ItemsSource = ((tblSOLedger)RoasterWerksDds.DataView.CurrentItem).tblSOLines;
      
                saleModal.Closed += new EventHandler(saleModal_Closed);
                saleModal.Show();

  2. Mark
    Mark avatar
    155 posts
    Member since:
    Oct 2010

    Posted 28 Apr 2011 Link to this post

    I was missing the DropQuery

    private void OnSOLineDropQuery(object sender, DragDropQueryEventArgs e)
           {
               if (e.Options.Source is GridViewHeaderCell || e.Options.Source is GridViewGroupPanelCell) return;
               ICollection draggedItems = e.Options.Payload as ICollection;
               bool result = draggedItems.Cast<object>().All((object item) => item is qryInventory);
               e.QueryResult = result;
               e.Handled = true;
           }


    Thanks for reading :)
  3. DevCraft banner
Back to Top