need help with gridview to treelistview

2 posts, 0 answers
  1. Rubric
    Rubric avatar
    2 posts
    Member since:
    Jun 2010

    Posted 26 Jul 2010 Link to this post

    I cant seem to get my head around dropping data from a gridview(students) to certain nodes in a treelistview(markers). Could I get any help?

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Data;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Telerik.Windows;
    using Telerik.Windows.Controls;
    using Telerik.Windows.Controls.DragDrop;
    using Telerik.Windows.Controls.TreeView;
    using InfoSys342.UI.ViewModels;
    namespace InfoSys342.UI
        public partial class MarkersByStudentView : UserControl
            private MarkersViewModel viewModel;
            private StudentsViewModel viewModel2;
            private ObservableCollection<String> list { get; set; }
            StudentMark ss = new StudentMark();
            public MarkersByStudentView(MainViewModel mainViewModel)
                this.viewModel2 = new MarkersViewModel(mainViewModel);
                this.mlist.DataContext = this.viewModel2;
                this.viewModel = new StudentsViewModel(mainViewModel);
                this.sList.DataContext = this.viewModel;
                RadDragAndDropManager.AddDragQueryHandler(this.mlist, new EventHandler<DragDropQueryEventArgs>(OnDragQuery));
                RadDragAndDropManager.AddDragInfoHandler(this.mlist, new EventHandler<DragDropEventArgs>(OnDragInfo));
                RadDragAndDropManager.AddDropQueryHandler(this.sList, OnDropQuery);
                RadDragAndDropManager.AddDropInfoHandler(this.sList, OnDropInfo);
            private void OnDragQuery(object sender, DragDropQueryEventArgs e)
                //We are asked here if the item should be dragged:
                if (e.Options.Status == DragStatus.DragQuery)
                    //The answer is yes, but we can get e.Options.Source and
                    //check the item for something and only then allow it.
                    e.QueryResult = true;
                    //Generally it is a good idea to handle routed events if
                    //we are taking some action.
                    e.Handled = true;
                    //We want to make sure that the payload is something maningful that can
                    //be used by the destination side. We could simply add the dragged item (or items)
                    //or we could create a custom class that will provide more information in
                    //a complex app.
                    //Here we get the ViewModel iitem. We could get the selected items of a cotnrol
                    //for multiple items DragDrop.
                    RadTreeListView treeView = e.Options.Source as RadTreeListView;
                    if (treeView != null && treeView.SelectedItem != null)
                        e.Options.Payload = treeView.SelectedItem;
                        e.Options.Payload = (e.Source as FrameworkElement).DataContext;
                    //We can decide to add a drag cue here
                    //to help the user. We can add any ContentControl as a
                    //drag cue but we can also generate an arrow because it is easier:
                    e.Options.ArrowCue = RadDragAndDropManager.GenerateArrowCue();
            private void OnDragInfo(object sender, DragDropEventArgs e){
                //We want to remove the item on a successful drop. But we have added
                //this event handler to the root visual, we have to then check the
                //drag source here. Alternatively we can add separates handlers to
                //the different controls.
                if (e.Options.Status == DragStatus.DragComplete)
                    IList itemsSource = null;
                    if (e.Options.Destination is Telerik.Windows.Controls.RadTreeListView)
                        itemsSource = (e.Options.Destination as Telerik.Windows.Controls.RadTreeListView).ItemsSource as IList;
                        itemsSource = (e.Options.Destination as RadTreeListView).ItemsSource as IList;
                   // itemsSource.Remove(e.Options.Payload);
            private void OnDropQuery(object sender, DragDropQueryEventArgs e)
                //Again, we handle the drop query at a root leve, but we could
                //add the handler to a specific control if we want more granularity.
                if (e.Options.Status == DragStatus.DropDestinationQuery)
                    //We would only check that the source and the destination are
                    e.QueryResult = e.Options.Destination != e.Options.Source;
                    e.Handled = true;
            private void OnDropInfo(object sender, DragDropEventArgs e)
                //Here we can change the drag cue to let the user know what
                //action is possible. We could change the background of the
                //arrow if it is in use.
                if (e.Options.Status == DragStatus.DropPossible)
                    //Drop is possible, change the content of the DragCue or
                    //notify the user that a drag is possible.
                if (e.Options.Status == DragStatus.DropImpossible)
                    //Drop is not possible. Here generally we will revert the changes
                    //done in DropPossible.
                if (e.Options.Status == DragStatus.DropComplete)
                    //Here we can generally check the payload and add handle the case
                    //when it is an IEnumerable (when multiple items are dragged).
                    //The paylaod could also be a custom class that contains mroe info
                    //for the DragDrop. HEre we know that it always is an item that we can
                    //display. We just add the item here, we do not interact with the
                    //drag source. Removing the item (if at all removed should happen OnDragIndo
                    //so that there will be separation of handling the DragDrop, which is more flexible.
                    IList itemsSource = null;
                    if (e.Options.Destination is Telerik.Windows.Controls.RadTreeListView)
                        itemsSource = (e.Options.Destination as Telerik.Windows.Controls.RadTreeListView).ItemsSource as IList;
                        itemsSource = (e.Options.Destination as RadTreeListView).ItemsSource as IList;


    <UserControl x:Class="InfoSys342.UI.MarkersByStudentView"
            <Style TargetType="TextBlock" x:Key="LabelStyle">
                <Setter Property="Margin" Value="0,0,3,0" />
            <Style TargetType="TextBlock" x:Key="ValueStyle">
                <Setter Property="Margin" Value="0,0,3,0" />
                <Setter Property="FontWeight" Value="Bold" />
            <local:PercentageToColourConverter x:Key="ColourConverter" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            <Border CornerRadius="3" Padding="3" Background="White" BorderBrush="#888888" BorderThickness="1" Margin="0,0,10,0">
                <grid:RadDockPanel LastChildFill="True">
                    <gridView:RadGridView AutoGenerateColumns="True" x:Name="mlist" dragDrop:RadDragAndDropManager.AllowDrop="True" ItemsSource="{Binding Students}" CanUserDeleteRows="False" CanUserInsertRows="False" IsReadOnly="True" RowIndicatorVisibility="Collapsed" ShowInsertRow="False" SelectionMode="Single" SelectedItem="{Binding CurrentStudent, Mode=TwoWay}" ShowGroupPanel="False">
                            <Style TargetType="gridViewElements:GridViewRow">
                                <Setter Property="dragDrop:RadDragAndDropManager.AllowDrag" Value="True"/>
            <controls:GridSplitter HorizontalAlignment="Right" VerticalAlignment="Stretch" Width="10" Margin="0,3" Background="Transparent" />
            <Border Grid.Column="1" CornerRadius="3" Padding="3" Background="White" BorderBrush="#888888" BorderThickness="1">
                <grid:RadDockPanel LastChildFill="True">
                    <gridView:RadTreeListView x:Name="sList"  dragDrop:RadDragAndDropManager.AllowDrop="True" ItemsSource="{Binding Staff}" CanUserDeleteRows="False" CanUserInsertRows="True" IsReadOnly="False" RowIndicatorVisibility="Collapsed" ShowInsertRow="False" SelectionMode="Single" SelectedItem="{Binding CurrentStudent, Mode=TwoWay}" ShowGroupPanel="False" AllowDrop="True">
                            <Style TargetType="gridView:RadTreeListView">
                                <Setter Property="dragDrop:RadDragAndDropManager.AllowDrop" Value="True" />
                                <Setter Property="Foreground" Value="Red" />

  2. Yavor Georgiev
    Yavor Georgiev avatar
    982 posts

    Posted 28 Jul 2010 Link to this post

    Hi Rubric,

     Could you please open a support ticket and attach your application? Also, it would be very helpful if you could explain in some detail what is your scenario and what you're trying to accomplish.

    Yavor Georgiev
    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
  3. DevCraft banner
Back to Top