Drag and drop into Radgrid

3 posts, 1 answers
  1. Surya
    Surya avatar
    35 posts
    Member since:
    Nov 2011

    Posted 20 May 2014 Link to this post

    Hi ,

     I have a requirement that need to drag and drop file from email client ( ex : outlook ) to radgridview .

    I am able to drag and drop from physical path to radgridview.

    Please do the needful.

    Thanks
    Surya.
  2. Answer
    Dess
    Admin
    Dess avatar
    1609 posts

    Posted 23 May 2014 Link to this post

    Hello Surya,

    Thank you for writing.

    It is possible to achieve the drag and drop functionality from Outlook to RadGridView using the OLE drag-and-drop functionality. Here is a sample code snippet, demonstrating dragging an attachment from Outlook and dropping it to RadGridView. As a result a new row in the grid with the file name is inserted:
    public Form1()
    {
        InitializeComponent();
        this.radGridView1.AllowDrop = true;
        this.radGridView1.DragDrop += radGridView1_DragDrop;
        this.radGridView1.DragEnter += radGridView1_DragEnter;
       
    }
     
    private void radGridView1_DragEnter(object sender, DragEventArgs e)
    {
        e.Effect = DragDropEffects.All;
    }
     
    private void radGridView1_DragDrop(object sender, DragEventArgs e)
    {
        using (Stream o2 = (Stream)e.Data.GetData("FileGroupDescriptorW"))
        {
            using (StreamReader sr = new StreamReader(o2, System.Text.Encoding.Unicode))
            {
                string draggedFileName = sr.ReadToEnd();
     
                Microsoft.Office.Interop.Outlook.Application outlook = new Microsoft.Office.Interop.Outlook.Application();
                Microsoft.Office.Interop.Outlook.Selection sel = outlook.ActiveExplorer().Selection;
                foreach (object item in sel)
                {
                    if (item is Microsoft.Office.Interop.Outlook.MailItem)
                    {
                        Microsoft.Office.Interop.Outlook.MailItem mail = item as Microsoft.Office.Interop.Outlook.MailItem;
                        Console.WriteLine("Email from " + mail.SenderName + " Regarding " + mail.Subject + " " + mail.Attachments.Count);
     
                        foreach (Microsoft.Office.Interop.Outlook.Attachment attachment in mail.Attachments)
                        {
                            if (draggedFileName.Contains(attachment.FileName))
                            {
                                this.radGridView1.Rows.Add(attachment.FileName);
                            }
                        }
                    }
                }
            }
        }
    }

    I would like to note that this is just a sample implementation and it may not cover all possible cases. Feel free to modify it on a way, which suits your requirement best. I think that "C# WinForms: Identify type of drag-drop action event" stackoverflow thread is useful about this topic.

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Surya
    Surya avatar
    35 posts
    Member since:
    Nov 2011

    Posted 26 May 2014 in reply to Dess Link to this post

    Hi Desislava,

     Thanks for responding and its works for me .


Back to Top