Treeview databinding help needed

5 posts, 0 answers
  1. ajin prasad
    ajin prasad avatar
    19 posts
    Member since:
    May 2010

    Posted 12 Dec 2011 Link to this post

    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.....

  2. Trude
    Trude avatar
    222 posts
    Member since:
    Jun 2009

    Posted 12 Dec 2011 Link to this post

    Your data needs to be contained in an ObservableCollection if drag & drop is to work.
  3. ajin prasad
    ajin prasad avatar
    19 posts
    Member since:
    May 2010

    Posted 12 Dec 2011 Link to this post

    can u provide a sample code for that?
  4. Trude
    Trude avatar
    222 posts
    Member since:
    Jun 2009

    Posted 13 Dec 2011 Link to this post

    From the Telerik blogs:

    http://blogs.telerik.com/blogs/posts/09-08-26/self-reference-hierarchy-with-telerik-treeview-for-silverlight.aspx

    Also, search the treeview forum and look at the online documentation for the treeview
  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    3151 posts

    Posted 15 Dec 2011 Link to this post

    Hello Ajin,

     I think you may find this blog post useful. It shows a drag and drop operation in the RadTreeView when it is bound to data from DB. The key thing that you may use is to create a "wrapper" ViewModels that will wrap the classes from the database. This way you are able to use ObservableCollection<> which are mandatory in drag and drop scenarios. Please let us know if the blog post helped you.

    Best wishes,
    Petar Mladenov
    the Telerik team

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

Back to Top