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

Error 'Value does not fall within the expected range'

2 Answers 122 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Vinay
Top achievements
Rank 1
Vinay asked on 10 Jun 2011, 07:25 AM
Hi,
I have a problem with my Drag Drop Functionality with TileView.

After Loading I am able to Drag and Drop the content from ListBox to TileView.(Actually its swapping). 
But when i Drag and Drop from within the TileView and after that again Drag and Drop from List Box i get an Error Stating
System.ArgumentException:Value Doesnot fall within Range.

Below is my code,
    <UserControl x:Class="Iatric.SAM.DashBoard.Reports"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             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"
             xmlns:telerik1="http://schemas.telerik.com/2008/xaml/presentation" mc:Ignorable="d">
    <UserControl.Resources>
        <DataTemplate x:Key="DragCueTemplate">
            <Button />
        </DataTemplate>
        <Style TargetType="ListBoxItem" x:Key="draggableItemStyle">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="telerik1:RadDragAndDropManager.AllowDrag" Value="True" />
        </Style>
    </UserControl.Resources>  
    <Grid x:Name="LayoutRoot" Background="White" VerticalAlignment="Top">
        <Grid.RowDefinitions>
            <RowDefinition Height="30" />           
            <RowDefinition Height="800" />
        </Grid.RowDefinitions>
        <ListBox x:Name="lstReportsContainer" telerik1:RadDragAndDropManager.AllowDrop="True" ItemContainerStyle="{StaticResource draggableItemStyle}" Grid.Row="0">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Border BorderBrush="#FFDADADA" BorderThickness="0,0,1,1" Height="131" CornerRadius="3" Margin="5">
                        <Border BorderBrush="#B2ADBDD1" BorderThickness="1" CornerRadius="2">
                            <StackPanel Orientation="Horizontal">
                                <Button Command="{Binding Tag}" Content="{Binding Content}" />                               
                            </StackPanel>
                        </Border>
                    </Border>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <telerikNavigation:RadTileView Name="tileDragDropPanel" Height="Auto"  MaximizeMode="Zero" 
                                       telerik1:RadDragAndDropManager.AllowDrop="True"
                                       IsItemDraggingEnabled="True" Grid.Row="2"
                                       TileStateChangeTrigger="None">
        </telerikNavigation:RadTileView>      
    </Grid>
</UserControl>
And the Code is,
Imports System.Collections.ObjectModel
Imports System.IO
Imports System.Xml.Linq
Imports Iatric.SAM.Infrastructure
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports Iatric.SAM.DashBoard.Controls
Imports Telerik.Windows.Controls.DragDrop
Imports Telerik.Windows.Controls
Imports Telerik.Windows
 
Partial Public Class Reports
    Inherits UserControl
    Private tileViewItemInfo As RadTileViewItem
    Dim currentTileView As List(Of String)
    Private Shared _viewList As New Dictionary(Of [String], Object)()
    Dim dragpostion As Integer
    Public Sub New()
        InitializeComponent()
        GetListViewItmes()
    End Sub
 
    Private Sub GetListViewItmes()
 
        BindData()
 
        RadDragAndDropManager.AddDragInfoHandler(lstReportsContainer, AddressOf OnDragInfo)
        RadDragAndDropManager.AddDragQueryHandler(lstReportsContainer, AddressOf OnDragQuery)
        RadDragAndDropManager.AddDropInfoHandler(tileDragDropPanel, AddressOf OnDropInfo)
        RadDragAndDropManager.AddDropQueryHandler(tileDragDropPanel, AddressOf OnDropQuery)
        RadDragAndDropManager.SetAllowDrop(tileDragDropPanel, True)
 
    End Sub
 
    Private Sub BindData()
        Dim MedicalIdentityReports As New ReportsLauncher(ReportLauncherElements.WebPartNames.MedicalIdentityRprt)
        Dim ActivityReports As New ReportsLauncher(ReportLauncherElements.WebPartNames.SAMReportActivity)
        Dim ExceptionReports As New ReportsLauncher(ReportLauncherElements.WebPartNames.PatientUserActivityExcpt)
        Dim DictionaryReports As New ReportsLauncher(ReportLauncherElements.WebPartNames.DictionaryEditActivity)
        Dim CareTakerReports As New ReportsLauncher(ReportLauncherElements.WebPartNames.Caretaker)
        Dim DialUpReports As New ReportsLauncher(ReportLauncherElements.WebPartNames.DialUpActivity)
 
        Dim incidentItemList As New List(Of UserControlProperties) From {
                     New UserControlProperties With {.UserControlName = "MedicalIdentityRprt", .UserControlCollection = MedicalIdentityReports},
                     New UserControlProperties With {.UserControlName = "SAMReportActivity", .UserControlCollection = ActivityReports},
                     New UserControlProperties With {.UserControlName = "DictionaryEditActivity", .UserControlCollection = DictionaryReports},
                     New UserControlProperties With {.UserControlName = "Caretaker", .UserControlCollection = CareTakerReports},
                     New UserControlProperties With {.UserControlName = "DialUpActivity", .UserControlCollection = DialUpReports},
                     New UserControlProperties With {.UserControlName = "PatientUserActivityExcpt", .UserControlCollection = ExceptionReports}
           }
 
        For Each incidentCollection In incidentItemList
            If (tileDragDropPanel.Items.Count < 4) Then
                Dim tileViewItem As New RadTileViewItem() With { _
                .Content = incidentCollection.UserControlCollection,
                .Tag = incidentCollection.UserControlName
            }
                'AddHandler tileViewItem.PositionChanged, AddressOf PositionChanged
                ' MouseLeftButtonDown += New MouseButtonEventHandler(Page_MouseLeftButtonDown)
                RadDragAndDropManager.SetAllowDrop(tileViewItem, True)
                Me.tileDragDropPanel.Items.Add(tileViewItem)
            Else
                Dim listBoxButton As New Button With {.Content = incidentCollection.UserControlName, .Tag = incidentCollection.UserControlName}
                lstReportsContainer.Items.Add(listBoxButton)
            End If
 
        Next
    End Sub
    Private Sub PositionChanged(ByVal sender As Object, ByVal e As PositionChangedEventArgs)
        Throw New NotImplementedException
    End Sub
    Private Sub OnDropInfo(ByVal sender As Object, ByVal e As DragDropEventArgs)
        Try
            Dim destination = e.Options.Destination
 
            If e.Options.Status = DragStatus.DropComplete Then
 
                If TypeOf destination Is RadTileView OrElse TypeOf destination Is RadTileViewItem Then
                    Dim header As String = String.Empty
                    Dim selectedSection As String = String.Empty
 
                    If DirectCast(DirectCast(e.Options.Source, System.Windows.Controls.ListBoxItem).Content, System.Windows.Controls.Button).Content IsNot Nothing Then
                        header = DirectCast(DirectCast(e.Options.Source, System.Windows.Controls.ListBoxItem).Content, System.Windows.Controls.Button).Tag
                        selectedSection = DirectCast(DirectCast(e.Options.Source, System.Windows.Controls.ListBoxItem).Content, System.Windows.Controls.Button).Content
                        AddPanel(selectedSection, header, DirectCast(destination, Telerik.Windows.Controls.RadTileViewItem), DirectCast(e.Options.Source, System.Windows.Controls.ListBoxItem))
                    End If
                End If
            End If
        Catch ex As Exception
 
        End Try
    End Sub
 
    Private Sub OnDropQuery(ByVal sender As Object, ByVal e As DragDropQueryEventArgs)
        Try
            Dim destination = e.Options.Destination
            e.QueryResult = True
            e.Handled = True
        Catch ex As Exception
 
        End Try
    End Sub
 
    Private Sub OnDragInfo(ByVal sender As Object, ByVal e As DragDropEventArgs)
        Try
            If e.Options.Status = DragStatus.DragComplete Then
            End If
        Catch ex As Exception
 
        End Try
    End Sub
 
    Protected Sub OnDragQuery(ByVal sender As Object, ByVal e As DragDropQueryEventArgs)
        Try
            If e.Options.Status = DragStatus.DragQuery Then
                Dim sourceListBoxItem = e.Options.Source
                 
                Dim DraggedItemName As String = DirectCast(DirectCast(sourceListBoxItem, System.Windows.Controls.ListBoxItem).Content, System.Windows.Controls.Button).Content
 
                Dim dragCue As New ContentControl()
                dragCue.Content = DraggedItemName
                dragCue.ContentTemplate = TryCast(Me.Resources("DragCueTemplate"), DataTemplate)
                e.Options.DragCue = dragCue
            End If
            e.QueryResult = True
            e.Handled = True
        Catch ex As Exception
        End Try
    End Sub
 
 
    Private Sub AddPanel(ByVal selectedSection As String, ByVal header As String, ByVal RemovedTileViewItem As RadTileViewItem, ByVal RemovedListBoxItem As System.Windows.Controls.ListBoxItem)
        Try
 
            Dim TileIndex As Integer = Me.tileDragDropPanel.Items.IndexOf(RemovedTileViewItem)
            Dim AddedtileViewItem = GetTileViewItem(selectedSection)
            RadDragAndDropManager.SetAllowDrop(AddedtileViewItem, True)
 
            Me.tileDragDropPanel.Items.RemoveAt(TileIndex)
            Me.tileDragDropPanel.Items.Insert(TileIndex, AddedtileViewItem)
 
 
            Dim ListIndex As Integer = Me.lstReportsContainer.Items.IndexOf(RemovedListBoxItem.Content)
            Dim listBoxButton As New Button With {.Content = RemovedTileViewItem.Tag, .Tag = RemovedTileViewItem.Tag}
            Me.lstReportsContainer.Items.RemoveAt(ListIndex)
            Me.lstReportsContainer.Items.Insert(ListIndex, listBoxButton)
        Catch ex As Exception
 
        End Try
    End Sub
 
    Private Function GetTileViewItem(ByVal selectedSection As String) As RadTileViewItem
        Select Case selectedSection
            Case "MedicalIdentityRprt"
                Dim AddedtileViewItem As New RadTileViewItem() With { _
             .Tag = selectedSection, _
             .Content = New ReportsLauncher(ReportLauncherElements.WebPartNames.MedicalIdentityRprt)
            }
                Return AddedtileViewItem
                Exit Function
            Case "SAMReportActivity"
                Dim AddedtileViewItem As New RadTileViewItem() With { _
             .Tag = selectedSection, _
             .Content = New ReportsLauncher(ReportLauncherElements.WebPartNames.SAMReportActivity)
            }
                Return AddedtileViewItem
                Exit Function
            Case "DictionaryEditActivity"
                Dim AddedtileViewItem As New RadTileViewItem() With { _
             .Tag = selectedSection, _
             .Content = New ReportsLauncher(ReportLauncherElements.WebPartNames.DictionaryEditActivity)
            }
                Return AddedtileViewItem
                Exit Function
            Case "PatientUserActivityExcpt"
                Dim AddedtileViewItem As New RadTileViewItem() With { _
             .Tag = selectedSection, _
             .Content = New ReportsLauncher(ReportLauncherElements.WebPartNames.PatientUserActivityExcpt)
            }
                Return AddedtileViewItem
                Exit Function
            Case "Caretaker"
                Dim AddedtileViewItem As New RadTileViewItem() With { _
             .Tag = selectedSection, _
             .Content = New ReportsLauncher(ReportLauncherElements.WebPartNames.Caretaker)
            }
                Return AddedtileViewItem
                Exit Function
            Case "DialUpActivity"
                Dim AddedtileViewItem As New RadTileViewItem() With { _
             .Tag = selectedSection, _
             .Content = New ReportsLauncher(ReportLauncherElements.WebPartNames.DialUpActivity)
            }
                Return AddedtileViewItem
                Exit Function
        End Select
    End Function
    End Class

2 Answers, 1 is accepted

Sort by
0
Accepted
Milan
Telerik team
answered on 10 Jun 2011, 09:03 AM
Hello vinay uthappa,

Could you please try to upgrade to our latest Internal Build. If that does not help, I would really appreciate it if you could send us the stack trace of the exception.


Kind regards,
Milan
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
0
Anita
Top achievements
Rank 2
answered on 18 May 2012, 06:03 PM
Stack trace of the above issue:

Type : System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Value does not fall within the expected range.,   at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
   at MS.Internal.XcpImports.MethodPack(IntPtr objectPtr, String methodName, Object[] rawData)
   at MS.Internal.XcpImports.UIElement_TransformToVisual(UIElement element, UIElement visual)
   at System.Windows.UIElement.TransformToVisual(UIElement visual)
   at Telerik.Windows.Controls.DragDrop.SimulatedDragDropProvider.AdjustScrollViewer(IScrollViewerAdapter viewer, Point currentPoint)
   at Telerik.Windows.Controls.DragDrop.SimulatedDragDropProvider.OnRealDrag(IMouseEventArgs e)
   at Telerik.Windows.Controls.DragDrop.SimulatedDragDropProvider.OnCoverRectangleMouseMoveInternal(IMouseEventArgs e)
   at Telerik.Windows.Controls.DragDrop.SilverlightDragDropProvider.OnCoverRectangleMouseMove(Object sender, MouseEventArgs e)
   at MS.Internal.CoreInvokeHandler.InvokeEventHandler(UInt32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName, UInt32 flags)

Tags
DragAndDrop
Asked by
Vinay
Top achievements
Rank 1
Answers by
Milan
Telerik team
Anita
Top achievements
Rank 2
Share this question
or