Hide a node driven

4 posts, 0 answers
  1. Cristina
    Cristina avatar
    1 posts
    Member since:
    Nov 2010

    Posted 30 Nov 2010 Link to this post

    Hi I have a Drag and Drop which can range from a RadGridView to a RadTreeView. I wish I could do the drag and drop but that the dragged item is not displayed in the RadTreeView, is hidden. This is the code I'm using:
    c#
    public Page()

     

    {

    InitializeComponent();

    this.GridView_ContentPlans.ItemsSource = DataGridView.GetContentPlans();

     

    this.GridView_ContentPlans.DataLoaded += new EventHandler<EventArgs>(GridView_ContentPlans_DataLoaded);

     

    LoadTreeFolders();

    RadDragAndDropManager.AddDragQueryHandler(GridView_ContentPlans, OnDragQuery);

     

     

     

    RadDragAndDropManager.AddDragInfoHandler(GridView_ContentPlans, OnDragInfo);

     

    TreeView_ContentPlans.AddHandler(

     

    RadDragAndDropManager.DropInfoEvent, new EventHandler<DragDropEventArgs>(OnDropInfo));
    }

     

    private

     

     

    void OnDragQuery(object sender, DragDropQueryEventArgs e)

     

    {

     

     

    if (e.Options.Status == DragStatus.DragQuery)

     

    {

    e.QueryResult =

     

    true;

     

     

     

    var dataGrid = sender as RadGridView;

     

     

     

    var items = GridView_ContentPlans.SelectedItems.Cast<ContentPlans>().ToList();

     

    e.Options.Payload = items;

     

     

     

     

     

     

     

    var dragCue = new TreeViewDragCue();

     

    dragCue.ItemsSource = items;

    dragCue.ItemTemplate =

     

    this.Resources[""] as DataTemplate;

     

    e.Options.DragCue = dragCue;

     

     

     

     

     

     

    }

     

     

    if (e.Options.Status == DragStatus.DropSourceQuery)

     

    {

    e.QueryResult =

     

    true;

     

    e.Handled =

     

    true;

     

    }

    }

     

    private

     

     

    void OnDragInfo(object sender, DragDropEventArgs e)

     

    {

     

     

    RadGridView gridView = sender as RadGridView;

     

     

     

    IEnumerable draggedItems = e.Options.Payload as IEnumerable;

     

     

     

    if (e.Options.Status == DragStatus.DragInProgress)

     

    {

     

     

    TreeViewDragCue cue = new TreeViewDragCue();

     

    cue.ItemTemplate =

     

    this.Resources[""] as DataTemplate;

     

    cue.ItemsSource = draggedItems;

    e.Options.DragCue = cue;

    }

     

     

    else if (e.Options.Status == DragStatus.DragComplete)

     

    {

     

     

    IList source = gridView.ItemsSource as IList;

     

     

     

    foreach (object draggedItem in draggedItems)

     

    {

    source.Remove(draggedItem);

     

    }

    }

    }

     

    private

     

     

    void LoadTreeFolders()

     

    {

     

     

    TreeViewFolder parentFolder1 = new TreeViewFolder();

     

    parentFolder1.Id =

     

    "1";

     

    parentFolder1.Name =

     

    "Content Plan Group 1";

     

    parentFolder1.CanCotnainEmployees =

     

    true;

     

     

     

    TreeViewFolder child1 = new TreeViewFolder();

     

    child1.Id =

     

    "11";

     

    child1.Name =

     

    "Sub Group 1.1";

     

    parentFolder1.Children.Add(child1);

    child1.CanCotnainEmployees =

     

    true;

     

     

     

    TreeViewFolder child11 = new TreeViewFolder();

     

    child11.Id =

     

    "111";

     

    child11.Name =

     

    "Sub Sub Group 1.1.1";

     

    child1.Children.Add(child11);

    child11.CanCotnainEmployees =

     

    true;

     

     

     

    TreeViewFolder parentFolder2 = new TreeViewFolder();

     

    parentFolder2.Id =

     

    "2";

     

    parentFolder2.Name =

     

    "Content Plan Group 2";

     

    parentFolder2.CanCotnainEmployees =

     

    true;

     

     

     

    TreeViewFolder child2 = new TreeViewFolder();

     

    child2.Id =

     

    "21";

     

    child2.Name =

     

    "Sub Group 2.1";

     

    parentFolder2.Children.Add(child2);

    child2.CanCotnainEmployees =

     

    true;

     

     

     

    TreeViewFolder parentFolder3 = new TreeViewFolder();

     

    parentFolder3.Id =

     

    "3";

     

    parentFolder3.Name =

     

    "Content Plan Group 3";

     

    parentFolder3.CanCotnainEmployees =

     

    true;

     

    folders.Add(parentFolder1);

    folders.Add(parentFolder2);

    folders.Add(parentFolder3);

     

     

    this.TreeView_ContentPlans.ItemsSource = folders;

     

    }


    public

     

     

    class ContentPlans

     

    {

     

     

    public string Name { get; set; }

     

     

     

    public string Size { get; set; }

     

     

     

    public int Panels { get; set; }

     

     

     

    public string Description { get; set; }

     

     

     

    private string _id;

     

     

     

    public string id

     

    {

     

     

    get { return _id; }

     

     

     

    set { _id = value; }

     

    }

    }


    XAML

    <

     

     

    telerik1:RadTreeView Margin="0,0,0,0"

     

     

     

    x:Name="TreeView_ContentPlans"

     

     

     

    Width="300"

     

     

     

    SelectionMode="Single"

     

     

     

    VerticalAlignment="Top"

     

     

     

    Grid.Column="0"

     

     

     

    Foreground="#FFFFFF"

     

     

     

    Background="Black"

     

     

     

    FontSize="13.333"

     

     

     

    FontFamily="Arial"

     

     

     

    IsExpandOnDblClickEnabled="True"

     

     

     

    IsDragTooltipEnabled="False"

     

     

     

    IsDragDropEnabled="True"

     

     

     

    telerik1:RadDragAndDropManager.AllowDrag="True"

     

     

     

    telerik1:TextSearch.TextPath="Id"

     

     

     

    telerik1:RadDragAndDropManager.AllowDrop="True"

     

     

     

    ItemContainerStyle="{StaticResource RadTreeViewItemStyle1}"

     

     

     

    PreviewDragEnded="TreeView_MediaFiles_PreviewDragEnded"

     

     

     

    Selected="RadTreeViewItem_Selected"

     

     

     

    >

     

     

     

     

     

    <telerik1:RadTreeView.ItemTemplate >

     

     

     

     

    <telerik1:HierarchicalDataTemplate ItemsSource="{Binding Children}" >

     

     

     

     

    <TextBlock Text="{Binding Name}" />

     

     

     

     

    </telerik1:HierarchicalDataTemplate>

     

     

     

     

    </telerik1:RadTreeView.ItemTemplate>

     

     

     

     

    </telerik1:RadTreeView>

     


    <

     

     

    telerik1:RadGridView Margin="0,3,0,0"

     

     

     

    Grid.Column="1"

     

     

     

    VerticalAlignment="Top"

     

     

     

    x:Name="GridView_ContentPlans"

     

     

     

    AlternateRowBackground="#FF262626"

     

     

     

    Background="#FF262626"

     

     

     

    BorderBrush="{x:Null}"

     

     

     

    ColumnBackground="#FF262626"

     

     

     

    Foreground="White"

     

     

     

    HorizontalGridLinesBrush="#FF8B8B8B"

     

     

     

    VerticalGridLinesBrush="{x:Null}"

     

     

     

    BorderThickness="0"

     

     

     

    GridLinesVisibility="Horizontal"

     

     

     

    ShowGroupPanel="False"

     

     

     

    HorizontalAlignment="Left"

     

     

     

    Width="800"

     

     

     

    Height="194"

     

     

     

    GroupPanelBackground="{x:Null}"

     

     

     

    FontSize="13.333"

     

     

     

    CanUserFreezeColumns="True"

     

     

     

    telerik1:RadDragAndDropManager.AllowDrag="True"

     

     

     

    >

     

    Thanks



  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 03 Dec 2010 Link to this post

    Hello Cristina,

    First of all, please accept our apologies for the late response.
    We prepared a sample project for you that implements the desired behavior. Please examine it and let us know if it works for you. It seems that when you remove the dragged items from the RadGridView (in the OnDragInfo event handler) the payload is also cleared. Therefore, since the built-in drop operations implemented in the RadTreeView control depend on the e.Options.Payload to add the dragged items in the RadTreeView Items collection, no items are really dropped.

    Therefore it would be better to remove the dragged items from the GridView Items collection after the drop in the tree is completed - you can use the RadTreeView.DragEnded event. Another approach is to add the dragged items in the tree manually, handling the DropInfo event of the RadTreeView.

    Feel free to ask if you need further assistance.

    Greetings,
    Petar Mladenov
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  3. DevCraft banner
  4. Cristina
    Cristina avatar
    16 posts
    Member since:
    Nov 2010

    Posted 13 Dec 2010 Link to this post

    Hello, thank you very much for answering my query. Actually what the draft shows who sent me is what actually makes my project. What I need is that the node is dragged to make the drag and drop is not shown in the treeview on the left. Thanks
  5. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 16 Dec 2010 Link to this post

    Hi Cristina,

    I am not sure if I understand you requirement correctly - do you want to add the dragged node into the RadTreeView collection but not display it? If this is the case, in a databound TreeView, you can define its ItemsSource collection as a collection that don't implement the INotifyCollectionChnaged interface. This way the RadTreeView control won't be aware of the changes made to its underlying collection and even when you add new items to it (by dragging from the RadGridView) they won't be displayed in the control. Such collection is the List collection.

    If, however, you want to drag an item from the RadGridView onto the RadTreeView without affecting the RadTreeView source collection at all, you can remove the RadTreeView DragEnded() event and handle the PreviewDragEnded() event instead:
    private void myTreeView_PreviewDragEnded(object sender, RadTreeViewDragEndedEventArgs e)
    {
        e.Handled = true;
        IList source = myGridView.ItemsSource as IList;
        foreach (object draggedItem in e.DraggedItems)
        {
            source.Remove(draggedItem);
        }
    }
    This way the dragged item will be removed from the RadGridView but it won't be added into the RadTreeView items collection.

    I hope this info helps.

    Regards,
    Tina Stancheva
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
Back to Top