Drag & Drop Files

4 posts, 0 answers
  1. Ashok
    Ashok avatar
    2 posts
    Member since:
    Mar 2011

    Posted 04 Feb 2013 Link to this post

    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
  2. Nick
    Admin
    Nick avatar
    593 posts

    Posted 05 Feb 2013 Link to this post

    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.

  3. Ashok
    Ashok avatar
    2 posts
    Member since:
    Mar 2011

    Posted 07 Feb 2013 Link to this post

    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
  4. Nick
    Admin
    Nick avatar
    593 posts

    Posted 07 Feb 2013 Link to this post

    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.

Back to Top