1

I have an application in silverlight 5. I use c1datagrid in our application. I want to drag and drop items from Desktop to our c1datagrid rows and while doing that I want to highlight that particular row in which I am dropping.

bytecode77
  • 14,163
  • 30
  • 110
  • 141
Pushpendra
  • 1,694
  • 14
  • 27

2 Answers2

1

One can Drag and drop in a silverlight application. Check "Require Elevated permissions" in silverlight project properties and using drop event of silverlight datagrid one can handle the drag and drop from desktop in a silverlight datagrid provided its not an OOB silverlight application.

private void DocumentsDrop(object sender, DragEventArgs e)
{
e.Handled = true;

var point = e.GetPosition(null);
var dataGridRow = ExtractDataGridRow(point);
if(dataGridRow !=null)
{.....
 }

var droppedItems = e.Data.GetData(DataFormats.FileDrop) as      FileInfo[];
if (droppedItems != null)
     {
        var droppedDocumentsList = new List<FileInfo>();

        foreach (var droppedItem in droppedItems)
        {
            if ((droppedItem.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
            {
                var directory = new DirectoryInfo(droppedItem.FullName);
                droppedDocumentsList.AddRange(directory.EnumerateFiles("*", SearchOption.AllDirectories));
            }
            else
            {
                droppedDocumentsList.Add(droppedItem);
            }
        }

        if (droppedDocumentsList.Any())
        {
            ProcessFiles(droppedDocumentsList);
        }
        else
        {
            DisplayErrorMessage("The selected folder is empty.");
        }
    }
 }      

Set AllowDrop =true; in xaml for the datagrid. From the DragEventArgs extract the information as FileInfo Object.

Pushpendra
  • 1,694
  • 14
  • 27
0

You cannot perform drag and drop operations from desktop to a silverlight application. It is a technological limitation.

Théo Winterhalter
  • 4,908
  • 2
  • 18
  • 34
  • You can Drag and drop in a silverlight application. Check "Require Elevated permissions" in silverlight project properties and using drop event of silverlight datagrid one can handle the drag and drop from desktop in a silverlight datagrid. private void Grid_Drop(object sender, DragEventArgs e) { MessageBox.Show("Yes we can drop"); } – Pushpendra Jul 28 '15 at 15:22