Profile Picture

Drag Drop (from external source) not working in NTreeList

Posted By Partho Sarathi 13 Years Ago

Drag Drop (from external source) not working in NTreeList

Author
Message
Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
Hello Partho,

To do that you need to create a new NTreeView class which overrides OnDragEnter and OnDragOver methods similar to the following:

public class MyNTreeList : NTreeList
{
   protected override void OnDragEnter(DragEventArgs drgevent)
   {
      base.OnDragEnter(drgevent);
      if (drgevent.Data.GetDataPresent(DataFormats.FileDrop))
         drgevent.Effect = DragDropEffects.Copy;
   }

   protected override void OnDragOver(DragEventArgs drgevent)
   {
      base.OnDragOver(drgevent);
      if (drgevent.Data.GetDataPresent(DataFormats.FileDrop))
         drgevent.Effect = DragDropEffects.Copy;
   }
}

Then you should attach to DragDrop event of the new class and in the event handler you can should create a new NTreeListNode with the appropriate sub items for each dragged file:

void nTreeList1_DragDrop(object sender, DragEventArgs e)
{
   string[] fileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);
   if (fileList == null)
      return;

   for (int i = 0; i < fileList.Length; i++)
   {
      NTreeListNode node = new NTreeListNode();

      NTreeListNodeStringSubItem item = new NTreeListNodeStringSubItem(fileList[i]);
      item.Column = nTreeList1.Columns[0];
      node.SubItems.Add(item);
      nTreeList1.Nodes.Add(node);
   }
}

I hope this helps.

Best Regards,
Nevron Support Team



Partho Sarathi
Posted 13 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 9, Visits: 1
Actually, I am trying to drag and drop a file from Windows Explorer. I am using the following as an example: http://www.jonasjohn.de/snippets/csharp/drag-and-drop-example.htm

Thanks,

Partho

Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
Hello Partho,

If you want to drag and drop sub items in the same NTreeList all you need to do is to set ItemDragDropMode property to ItemDragDropMode.Local.
This way you will be able to drag and drop items into the list.
If you want to move item in the same level you need to hold Shift key while dragging.
If you want to copy the dragged item you need to hold Control key.

To be able to drag and drop items between two NTreeList controls you need to set ItemDragDropMode to ItemDragDropMode.Global to both controls and to drop an item on NTreeList you need to have at least one item in it.

The events related to dragging items here are ItemBeginDrag, ItmeDrag and ItemDragComplete.

Best Regards,
Nevron Support Team



Partho Sarathi
Posted 13 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 9, Visits: 1
I am using the following code to handle a drag drop of a windows explorer file.


public Form1()
{
InitializeComponent();

treeList.AllowDrop = true;
treeList.DragEnter += treeList_DragEnter;
treeList.DragDrop += treeList_DragDrop;
}

private void treeList_DragDrop(object sender, DragEventArgs e)
{
string[] files = (string[]) e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files)
{
FileInfo info = new FileInfo(file);
treeList.Nodes.Add(new NTreeListNode
{
SubItems =
{
new NTreeListNodeStringSubItem(info.Name)
{Column = treeList.Columns["Name"]},
new NTreeListNodeStringSubItem(info.Length.ToString())
{Column = treeList.Columns["Size"]}
}
});
}
}

private void treeList_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}


Dragging files to the NTreeList control does not show the Copy cursor, even though the DragEnter handler is called. The DragDrop handler is not called.

Similar code works for Microsoft's ListView.



Similar Topics


Reading This Topic