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

SelectedItem Null on DragQuery

0 Answers 55 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Vinay
Top achievements
Rank 1
Vinay asked on 03 Jun 2011, 12:27 PM
Hi,
I have a simple DragDrop from ListBox to TileView Implimentation.
I am not getting the Selected Item on Drag.
On DragQueryEvent i get Dim box As ListBox = TryCast(ItemsControl.ItemsControlFromItemContainer(listBoxItem), ListBox)
as Nothing.
e.option.selectedItem is also Nothing
Below is my XAML,
<UserControl x:Class="Iatric.SAM.DashBoard.Reports" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:telerikControl="clr-namespace:Telerik.Windows.Controls.DragDrop;assembly=Telerik.Windows.Controls" xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" xmlns:dragDrop="clr-namespace:Telerik.Windows.Controls.DragDrop;assembly=Telerik.Windows.Controls" xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" xmlns:telerikStyle="http://schemas.telerik.com/2008/xaml/presentation" xmlns:System="clr-namespace:System;assembly=mscorlib" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400">
 
     
    <Grid x:Name="LayoutRoot" Width="Auto" Background="#dbe6ea">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Border BorderBrush="#bed8d9" BorderThickness="1" Background="White" Margin="5" CornerRadius="5" Height="Auto" Width="Auto">
            <StackPanel Orientation="Vertical" Grid.Column="0" Grid.Row="1">
                <Border BorderBrush="#bed8d9" Margin="10" BorderThickness="1" Background="White" CornerRadius="3" Height="460">
                    <telerikNavigation:RadTileView Name="dragDockPanelHost" Height="460" telerikControl:RadDragAndDropManager.AllowDrop="True" IsItemDraggingEnabled="True" Grid.Row="0" Grid.Column="0">
                    </telerikNavigation:RadTileView>
                </Border>
 
                <telerik:RadWrapPanel x:Name="imageContainer" IsAnimated="True" UseLayoutRounding="True">
                    <ListBox VerticalAlignment="Top" x:Name="lstExpandView" BorderBrush="Brown" BorderThickness="1" dragDrop:RadDragAndDropManager.AllowDrag="True" dragDrop:RadDragAndDropManager.AllowDrop="True" Height="103">
                    </ListBox>
                </telerik:RadWrapPanel>
            </StackPanel>
        </Border>
 
    </Grid>
 
</UserControl>

And here is my VB code,
Imports System.Collections.ObjectModel
Imports System.IO
Imports System.Xml.Linq
Imports Iatric.SAM.Infrastructure
Imports Iatric.SAM.DashBoard.Controls
Imports Telerik.Windows.Controls.DragDrop
Imports Telerik.Windows.Controls
Imports Telerik.Windows
 
Partial Public Class Reports
    Inherits UserControl
    Public Sub New()
        Try
            InitializeComponent()
            GetListViewItmes()
        Catch ex As Exception
            Dim ex1 As String = ex.Message
        End Try
    End Sub
    Private Sub GetListViewItmes()
 
        Dim btnList As New List(Of Button) From {
        New Button With {.Name = "btn1", .Content = "Medical Identity Reports"},
        New Button With {.Name = "btn2", .Content = "Activity Reports"},
        New Button With {.Name = "btn3", .Content = "Dictionary Edit Reports"},
        New Button With {.Name = "btn4", .Content = "CareTaker Reports"},
        New Button With {.Name = "btn5", .Content = "Dial Up Reports"}
   }
        lstExpandView.ItemsSource = btnList
        lstExpandView.DataContext = btnList
        lstExpandView.DisplayMemberPath = "Content"
        lstExpandView.SelectedValuePath = "Name"
 
        RadDragAndDropManager.AddDragInfoHandler(lstExpandView, AddressOf OnDragInfo)
        RadDragAndDropManager.AddDragQueryHandler(lstExpandView, AddressOf OnDragQuery)
        RadDragAndDropManager.AddDropInfoHandler(dragDockPanelHost, AddressOf OnDropInfo)
        RadDragAndDropManager.AddDropQueryHandler(dragDockPanelHost, AddressOf OnDropQuery)
        RadDragAndDropManager.SetAllowDrop(dragDockPanelHost, True)
        EventManager.RegisterClassHandler(GetType(RadTileViewItem), RadDragAndDropManager.DropInfoEvent, New EventHandler(Of DragDropEventArgs)(AddressOf OnDropInfo), True)
    End Sub
 
    Private Sub OnDropInfo(ByVal sender As Object, ByVal e As DragDropEventArgs)
        Dim box As ItemsControl = TryCast(e.Options.Destination, ItemsControl)
        Dim itemsSource As IList(Of Button) = TryCast(box.ItemsSource, IList(Of Button))
        Dim payload As Button = TryCast(e.Options.Payload, Button)
        If e.Options.Status = DragStatus.DropComplete Then
            If Not itemsSource.Contains(payload) Then
                itemsSource.Add(payload)
            End If
        End If
    End Sub
 
    Private Sub OnDropQuery(ByVal sender As Object, ByVal e As DragDropQueryEventArgs)
        Dim box As ItemsControl = TryCast(e.Options.Destination, ItemsControl)
        Dim itemsSource As IList(Of Button) = TryCast(box.ItemsSource, IList(Of Button))
        Dim payload As Button = TryCast(e.Options.Payload, Button)
        e.QueryResult = payload IsNot Nothing AndAlso Not itemsSource.Contains(payload)
    End Sub
 
    Private Sub OnDragInfo(ByVal sender As Object, ByVal e As DragDropEventArgs)
        Dim listBoxItem As ListBoxItem = TryCast(e.Options.Source, ListBoxItem)
        Dim box As ListBox = TryCast(ItemsControl.ItemsControlFromItemContainer(listBoxItem), ListBox)
        Dim itemsSource As IList(Of Button) = TryCast(box.ItemsSource, IList(Of Button))
        Dim payload As Button = TryCast(e.Options.Payload, Button)
        If e.Options.Status = DragStatus.DragComplete Then
            If payload IsNot Nothing AndAlso itemsSource.Contains(payload) Then
                itemsSource.Remove(payload)
            End If
        End If
    End Sub
 
    Protected Sub OnDragQuery(ByVal sender As Object, ByVal e As DragDropQueryEventArgs)
        Dim listBoxItem As ListBoxItem = TryCast(e.Options.Source, ListBoxItem)
        Dim box As ListBox = TryCast(ItemsControl.ItemsControlFromItemContainer(listBoxItem), ListBox)
        If e.Options.Status = DragStatus.DragQuery AndAlso box IsNot Nothing Then
            e.Options.Payload = box.SelectedItem
            Dim cue As New ContentControl()
            cue.ContentTemplate = TryCast(Me.Resources("ApplicationDragTemplate"), DataTemplate)
            cue.Content = box.SelectedItem
            e.Options.DragCue = cue
            e.Options.ArrowCue = RadDragAndDropManager.GenerateArrowCue()
        End If
        e.QueryResult = True
    End Sub
End Class

No answers yet. Maybe you can help?

Tags
DragAndDrop
Asked by
Vinay
Top achievements
Rank 1
Share this question
or