RadTreeViewItem Background Color

6 posts, 0 answers
  1. WILLIAM
    WILLIAM avatar
    134 posts
    Member since:
    Jun 2012

    Posted 03 Apr 2014 Link to this post

    Hi Telerik Team,

    I've recently upgraded to the 2014 Q1 version.  I have a RadGridView where I'm dragging and dropping items into folders in RadTreeView.  I have everything working except for one thing.

    Previously, when items were being dragged over the folders, the background of the item you were over changed to a light blue; it's the same color as when the mouse is over the folder when not dragging.  This is not happening now, and I haven't figured out a way to make that happen.  I looked through the code the previous developer wrote and it doesn't look like he was doing anything to specifically set the background.  I think it was just happening automatically.  Has this changed?  How do I make it do that?  I need to do be able to do this in the code-behind; not the xaml.

    Thanks for your help!!
  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 08 Apr 2014 Link to this post

    Hi William,

    I am not sure which version of our controls you have upgraded from. This is why I cannot be sure for the reasons behind. Please note that recently we did not make any changes to the drag drop logic of the RadTreeView.

    However, when working with the RadTreeView control in drag drop scenarios, you need to keep in mind that currently the RadTreeView supports two built in drag/drop modes. These modes are selected by the TreeViewSettings.DragDropExecutionMode property. If you set it to Legacy  (this is the default value) the control will use the deprecated RadDragAndDropManager, if you set it to New the control utilizes the DragDropManager. For more information you can take a look at our documentation.

    I hope this information is helpful.

    Regards,
    Pavel R. Pavlov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. DevCraft banner
  4. WILLIAM
    WILLIAM avatar
    134 posts
    Member since:
    Jun 2012

    Posted 08 Apr 2014 in reply to Pavel R. Pavlov Link to this post

    Previous Version: 2012.3.1129.1050
    Current Version: 2014.1.224.1050

    I have set the TreeViewSettings.DragDropExecutionMode = New, however, the node still does not "highlight" as I drag items over it.

    ??

    Thanks for your help!
  5. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 11 Apr 2014 Link to this post

    Hello,

    I tried to reproduce the reported issue on our side and it seems that the code works as expected. Could you please change the code of the attached project so that the issue can be reproduced and sent it over? By doing so I will be able to reproduce it on our side and further investigate the reasons behind.

    Thank you for your king cooperation.

    Regards,
    Pavel R. Pavlov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. WILLIAM
    WILLIAM avatar
    134 posts
    Member since:
    Jun 2012

    Posted 11 Apr 2014 Link to this post

    I see the difference and my initial explanation may have not been clear.  In your example, dragging items from one folder to the next does work.  We do not allow dragging items from one folder to another, so I'm not sure if that scenario is working for us or not.  We are dragging rows from a grid view and dropping them in a folder.  I'm not sure if that should make a difference.

    Here is my code-behind.  This may help identify what I'm doing wrong, or if I have left something out.  I probably should have posted this in the first place.  Sorry about that!  I'm not the original developer of this code.  I just tried to implement the new DragDropManager.

    This is the code for allowing Drag from a grid view:
    private WeakReferenceOf<DataControl> _dataControl;
     
           public void Initialize(DataControl control)
           {
               _dataControl = new WeakReferenceOf<DataControl>(control);
               ConfigureControl();
           }
     
           private void ConfigureControl()
           {
               DragDropManager.SetAllowDrag(_dataControl.Target, true);
               DragDropManager.AddDragInitializeHandler(_dataControl.Target, OnDragInitialize);
           }
     
           /// <summary>
           /// Start dragging. Create Drag Cue by apllying custom Template
           /// </summary>
           private static void OnDragInitialize(object sender, DragInitializeEventArgs e)
           {
               var control = e.Source as DataControl;
               if (control == null)
               {
                   e.Handled = false;
                   return;
               }
     
               var items = control.SelectedItems
                   .Where(si => si as IFolderEntity != null)
                   .Select(i => i as IFolderEntity)
                   .ToList();
     
               if (!items.Any())
               {
                   e.Handled = true;
                   return;
               }
     
               var payLoad = DragDropPayloadManager.GeneratePayload(null);
               payLoad.SetData("DraggedData", items);
                
               e.AllowedEffects = DragDropEffects.Move;
               e.Data = payLoad;
               e.DragVisual = null;
               e.Handled = true;
           }
     
           public void UnregisterEvents()
           {
               DragDropManager.RemoveDragInitializeHandler(_dataControl.Target, OnDragInitialize);
               _dataControl = null;
           }

    This is the code for TreeView when dropping:
    private RadTreeView TreeView { get; set; }
     
            public void Initialize(RadTreeView treeView)
            {
                TreeView = treeView;
                TreeView.ItemPrepared += TreeViewOnItemPrepared;
            }
     
            private void TreeViewOnItemPrepared(object sender, RadTreeViewItemPreparedEventArgs e)
            {
                DragDropManager.RemoveDragOverHandler(e.PreparedItem, OnItemDragOver);
                DragDropManager.RemoveDropHandler(e.PreparedItem, OnDrop);
                DragDropManager.AddDragOverHandler(e.PreparedItem, OnItemDragOver);
                DragDropManager.AddDropHandler(e.PreparedItem, OnDrop);
            }
     
            private void OnItemDragOver(object sender, TDragEventArgs e)
            {
                var item = (e.OriginalSource as FrameworkElement).ParentOfType<RadTreeViewItem>();
                item.AllowDrop = false;
     
                var folder = item.GetFolder();
                if (folder == null || !folder.FolderTypeCode.CanDrop)
                {
                    e.Handled = true;
                    return;
                }
     
                var draggedData = DragDropPayloadManager.GetDataFromObject(e.Data, "DraggedData");
                var fe = ((List<IFolderEntity>)draggedData).FirstOrDefault();
                if (fe == null)
                {
                    e.Handled = true;
                    return;
                }
     
                var tmpFolder = folder;
                //Loop up the parents until you find the child of the WorkSpace folder
                while (tmpFolder.ParentFolder.FolderTypeCode.Id != FolderTypeCode.Workspace.Id)
                {
                    tmpFolder = tmpFolder.ParentFolder;
                }
     
                if (tmpFolder.FolderTypeCode.Id != fe.FolderTypeCode.Id)
                {
                    e.Handled = true;
                    return;
                }
     
                item.AllowDrop = true;
                e.Handled = true;
            }
     
            private void OnDrop(object sender, TDragEventArgs e)
            {
                var item = (e.OriginalSource as FrameworkElement).ParentOfType<RadTreeViewItem>();
     
                var draggedData = DragDropPayloadManager.GetDataFromObject(e.Data, "DraggedData");
                if (draggedData == null) return;
     
                var folderEntities = draggedData as IEnumerable<IFolderEntity>;
                if (folderEntities == null) return;
     
                CreateFolderEntities(item, folderEntities);
                e.Handled = true;
            }

  7. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 15 Apr 2014 Link to this post

    Hello WILLIAM,

    I can see that in your code you actually restrict the RadTreeView control to visualize any DragVisual. In the OnDragInitialize() method you set the e.DragVisual to null. I am not sure what you wanted to achieve by setting that property to null but the expected result is that the DragVisual will not be visualized.
    Hence, the code is working as expected.

    Regards,
    Pavel R. Pavlov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
DevCraft banner