Hide a node driven

2 posts, 1 answers
  1. Cristina
    Cristina avatar
    16 posts
    Member since:
    Nov 2010

    Posted 01 Dec 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. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 06 Dec 2010 Link to this post

    Hello Cristina,

    Can you please have a look at this forum thread and let us know if the solution provided there works for you? Thank you in advance.

    All the best,
    Tina Stancheva
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  3. DevCraft banner
Back to Top