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

Drag/Drop with ItemsSource set to ListCollectionView

2 Answers 164 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 09 Feb 2009, 06:26 PM
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 Answers, 1 is accepted

Sort by
0
Tihomir Petkov
Telerik team
answered on 11 Feb 2009, 11:57 AM
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.
0
Martin
Top achievements
Rank 1
answered on 11 Feb 2009, 02:47 PM
Hi Tihomir,

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

Martin
Tags
TreeView
Asked by
Martin
Top achievements
Rank 1
Answers by
Tihomir Petkov
Telerik team
Martin
Top achievements
Rank 1
Share this question
or