Drag/Drop with ItemsSource set to ListCollectionView

3 posts, 0 answers
  1. Martin
    Martin avatar
    11 posts
    Member since:
    Jan 2009

    Posted 09 Feb 2009 Link to this post

    Hello,

    I am having trouble enabling drag/drop functionality in a RadTreeView when I set its ItemsSource to a ListCollectionView. Here is an example:

    <Window x:Class="WpfApplication6.Window1" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:Telerik="http://schemas.telerik.com/2008/xaml/presentation" 
        SizeToContent="WidthAndHeight" 
        Title="Window1"
        <Telerik:RadTreeView x:Name="sourceTree" Height="300" Width="300" IsDragDropEnabled="True"/> 
    </Window> 

        public partial class Window1 : Window 
        { 
            public Window1() 
            { 
                InitializeComponent(); 
     
                ObservableCollection<string> testCollection = new ObservableCollection<string>(); 
                testCollection.Add("one"); 
                testCollection.Add("two"); 
                testCollection.Add("three"); 
     
                ListCollectionView view = new ListCollectionView(testCollection); 
                sourceTree.ItemsSource = view; 
            } 
        } 

    The items display fine, but when I drag and drop them nothing seems to happen. If I set the ItemsSource directly to the testCollection, it works just fine, but I need to use a ListCollectionView in my case in order to enable filtering. Is this a bug in the control, or am I doing something improperly? Thanks.

  2. Tihomir Petkov
    Admin
    Tihomir Petkov avatar
    576 posts

    Posted 11 Feb 2009 Link to this post

    Hello Martin,

    RadTreeView needs a collection for its ItemsSource property in order to function correctly and that is why the drag and drop stops working when you set the ItemsSource to be your ListCollectionView. What you can do in your case though, is use the default view of your collection. You can do so as follows:

    sourceTree.ItemsSource = testCollection;
    ListCollectionView view = (ListCollectionView)CollectionViewSource.GetDefaultView(sourceTree.ItemsSource);

    Let me know if this solves your problem.

    All the best,
    Tihomir Petkov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Martin
    Martin avatar
    11 posts
    Member since:
    Jan 2009

    Posted 11 Feb 2009 Link to this post

    Hi Tihomir,

    Your solution is exactly what I was looking for. Thanks for the reply!

    Martin
Back to Top