This is a migrated thread and some comments may be shown as answers.

Drag & Drop Files

3 Answers 755 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ashok
Top achievements
Rank 1
Ashok asked on 04 Feb 2013, 03:45 PM
Hi,

Can you let us know how to implement drag & drop functionality of a file into RadGridView.
The grid should display the link to the file.

NOTE: Multiple files can be dropped.

Best Regards,
Varun R

3 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 05 Feb 2013, 04:11 PM
Hi Varun,

You can easily achieve it by using the following snippet:

public MainWindow()
        {
            InitializeComponent();
 
            DragDropManager.AddDropHandler(this.GridView, OnDrop);
            this.GridView.ItemsSource = this.Paths;
        }
 
        private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
        {
            var data = e.Data as DataObject;
 
            if (data != null && data.ContainsFileDropList())
            {
                var list = data.GetFileDropList();
 
                foreach (var path in list)
                {
                    this.Paths.Add(new FilePath() { Path = path });
                }
            }
        }

Hope it helps!  Kind regards,
Nik
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Ashok
Top achievements
Rank 1
answered on 07 Feb 2013, 07:34 AM
Hi Nik,

Thanks for the reply.
I had done the same implementation & it worked in my system.

But when i do the same in other PC (having same development environment of mine) the drop is not allowed.
The mouse icon shows a crossed symbol. I have set the AllowDrop property to true in the xaml file.

i tried in 2 more systems, but the same problem.
What could be the reason for this?

Code:
<telerik:RadGridView x:Name="dgAttchdDocs"  AllowDrop="True"
                     RowIndicatorVisibility="Collapsed"
                     CanUserFreezeColumns="False" AutoGenerateColumns="False"
                     GroupRenderMode="Flat" GridLinesVisibility="None"
                     IsReadOnly="True" ShowGroupPanel="False" HorizontalAlignment="Left">
  <telerik:RadGridView.Columns>
    <telerik:GridViewDataColumn UniqueName="Name"
                                Header="Attached Document"
                                DataMemberBinding="{Binding Name}"
                                Width="250"></telerik:GridViewDataColumn>
  </telerik:RadGridView.Columns>
</telerik:RadGridView>
 
In Constructor:
DragDropManager.AddDropHandler(this.dgAttchdDocs, OnDrop);
 
private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
{
    if (e.Effects != DragDropEffects.None)
    {
        var dataObject = e.Data as DataObject;
 
        if (dataObject != null && dataObject.ContainsFileDropList())
        {
            foreach (var item in dataObject.GetFileDropList())
            {
                if (item.ToString().Substring(item.ToString().Length - 4, 4).ToUpper() == ".PDF")
                {
                    EOAttachment Attachment = new EOAttachment();
                    Attachment.Name = System.IO.Path.GetFileName(item.ToString());
                    this.dgAttchdDocs.Items.Add(Attachment);
                }
                else
                {
                    MessageBox.Show("Only PDF files can be attached.", "Quantum", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
    }
}

Thanks,
Varun R
0
Nick
Telerik team
answered on 07 Feb 2013, 11:20 AM
Hi Varun,

Dragging operations between your applications and other ones, sometimes requires the application to be in FullTrust permissions. Can you check if the other machines don't offer the necessary permitions to your app?

Hope this helps! 

Regards,
Nik
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Ashok
Top achievements
Rank 1
Answers by
Nick
Telerik team
Ashok
Top achievements
Rank 1
Share this question
or