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

Treeview databinding help needed

1 Answer 54 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
ajin prasad
Top achievements
Rank 1
ajin prasad asked on 13 Dec 2011, 12:39 PM

Hi 

I am using drag drop treeview in my application .

the xaml is

<Grid.Resources>
            <telerik:HierarchicalDataTemplate x:Key="secondLevelTemplate">
                <TextBlock
                           
                           Text="{Binding Description}" />
            </telerik:HierarchicalDataTemplate>


            <telerik:HierarchicalDataTemplate x:Key="RootTemplate" 
                                              ItemsSource="{Binding GN_Properties}"
                                              ItemTemplate="{StaticResource secondLevelTemplate}">
                <TextBlock 
                           
                           Text="{Binding DevelopmentName}" />
            </telerik:HierarchicalDataTemplate>
        </Grid.Resources>
        <StackPanel Orientation="Horizontal">
            <telerik:RadTreeView x:Name="treeView1" 
                             HorizontalAlignment="Center"
                             IsDragDropEnabled="True"
                            
                             ItemTemplate="{StaticResource RootTemplate}" />
           
                <telerik:RadTreeView x:Name="treeView2" 
                             HorizontalAlignment="Center"
                             IsDragDropEnabled="True"
                            
                             ItemTemplate="{StaticResource RootTemplate}" />
            
        </StackPanel>


The two tables i used are GN_Developments and GN_Properties. these are foriegn key related.
In my first treeview i displayed all the developments and its properties vailable in database and in second treeview 
i displayed all developments and its properties choosen by the user.

I want to drag items from first treeview to second view.
the code behind is 

 LandlordDomainContext ctx = new LandlordDomainContext();
LandlordDomainContext ctx2 = new LandlordDomainContext();
treeView1.ItemsSource = ctx.GN_Developments;
ctx.Load(ctx.GetGN_DevelopementQuery(4));
treeView2.ItemsSource = ctx2.GN_Developments;
ctx2.Load(ctx2.GetGN_DevelopmentQuery(4));

the domain service class query is 
 public IQueryable<GN_Developments> GetGN_Development(int DevID)
{
return this.ObjectContext.GN_Developments.Include("GN_Properties").Where(s =>s.DevelopmentID==DevID);
}
public IQueryable<GN_Developments> GetGN_Developement(int DevID)
{
return this.ObjectContext.GN_Developments.Include("GN_Properties").Where(s => s.DevelopmentID != DevID);
}

The problem is I am getting values binded sucessfully in the page as per my query. But I cannot drag/drop items.
I am not able to drag items from firt treeview and drop to second treeview

Moreover how can i save the items on save button click if the items are dragged and dropped

My scenario is to drag items from first treeview to 2nd treeview and save it on button click.....

1 Answer, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 16 Dec 2011, 02:01 PM
Hi Ajin Prasad,

In order to use the drag/drop operations in a databound RadTreeView, you need to bind its ItemsSource to a collection that implements the INotifyCollectionChanged interface. The ObservableCollection<T> has a built-in implementation of a data collection that exposes the INotifyCollectionChanged interface. However, the WCF service returns an EntitySet which is of type IList and it doesn't implement the interface. Therefore when you use a WCF service to set the RadTreeView ItemsSource collection, the RadTreeView control won't be notified if the collection is changed.

When working with the RadTreeView control, you have to keep in mind that it is a data-driven control. So the drag/drop operations are implementing changes to the underlying ItemsSource collection in databound scenarios. Now, when you cannot notify the RadTreeView that the collection is changed - that a certain item is dragged and dropped to another place in the IList collection, the control won't be able to visually display those changes thus causing the issues you experienced.

In order to get over this behavior you can wrap the IList collection that the context provides in an ObservableCollection. I attached a sample project to illustrate this approach. Please give it a try and let me know if it works for you.

All the best,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
TreeView
Asked by
ajin prasad
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question
or