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

Drag and drop into Radgrid

2 Answers 175 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Surya
Top achievements
Rank 1
Surya asked on 20 May 2014, 05:52 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 May 2014, 11:39 AM
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.
 
0
Surya
Top achievements
Rank 1
answered on 26 May 2014, 10:15 AM
Hi Desislava,

 Thanks for responding and its works for me .


Tags
General Discussions
Asked by
Surya
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Surya
Top achievements
Rank 1
Share this question
or