Reputation: 293
I want to Drag and Drop something into a DataGrid in WinForms. The functionality that he recognises the Drag Enter and Drag Drop are made. It works like a charm because i made text pop up when it enters and when its dropped.
Sadly i have no idea how to access the content of the thing (Outlook Contact) i dropped in there. My Goal is to Drop and Outlook Contact into the Data Grid and i want to have the things contained in the Contact like, Name, Email adress etc. and save it temporarily so that i can insert it into the Grid.
I hope some of you can help me and/or give me a clue on how to tackle this.
Thanks in advance.
Upvotes: 0
Views: 170
Reputation: 2574
First, you need a reference to Microsoft.Office.Interop.Outlook
. There is a NuGet package for this.
Install-Package Microsoft.Office.Interop.Outlook
Create a instance for the Outlook.Application
and get the selected items in your DragDrop
Handler.
private Microsoft.Office.Interop.Outlook.Application moOutlook = new Microsoft.Office.Interop.Outlook.Application();
private void DragDropHandler(object sender, DragEventArgs e)
{
var loExplorer = moOutlook.ActiveExplorer();
var loSelection = loExplorer.Selection;
foreach (object loItem in loSelection)
{
Microsoft.Office.Interop.Outlook.ContactItem loContactItem = (loItem as Microsoft.Office.Interop.Outlook.ContactItem);
if (loContactItem != null)
{
Console.WriteLine(loContactItem.EntryID);
Console.WriteLine(loContactItem.Email1Address);
Console.WriteLine(loContactItem.Email2Address);
}
}
}
Upvotes: 1