Post selected contact items to an datagridview on form at the RightSubpane

Add-in Express™ Support Service
That's what is more important than anything else

Post selected contact items to an datagridview on form at the RightSubpane
Post items to an form 
Joachim Weber


Guest


Hallo,

I have to post selected contact items from the outlook explorer to an datagridview which is placed at an form. The form are placed at the RightSubpane of the explorer and it's only visible for contact. The posting process will be triggered if the user have clicked on an RibbonButton at the RibbonTab.
I catch the form like and try to get control to the datagriedview, but without success:


        private void MoveSelectedContactToCRM()
        {
            Outlook.ApplicationClass app = new Outlook.ApplicationClass();
            Outlook.Selection selContacts = app.ActiveExplorer().Selection;

            AddinExpress.OL.ADXOlForm testForm = adxOlFormsCollectionItem4.FormInstances(0);

            int nAnz = this.adxOlFormsCollectionItem4.FormInstanceCount;

            //Access the datagriedview to fill it with the selected contact items
            
            foreach (Outlook.ContactItem conItem in selContacts)
            {
                //conItem.
            }
        }


At this point i need the the datagridview control to fill it with the selected contact items.
How can I solve this??

Thanks for your help!!

Joachim
Posted 19 May, 2015 10:37:25 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hallo Joachim,

You can use ADXOlFormsCollectionItem.GetForm() to get the form instance shown in the specified Outlook window. Then you cast the result to the type of your form (e.g. MyAddin1.MyADXOlForm1) and access the grid.


Andrei Smolin
Add-in Express Team Leader
Posted 20 May, 2015 04:53:46 Top
Joachim Weber


Guest


Hallo Andrei,

thanks for your answer! Now it work fine. For developers which are having the same problem, here are the complete code to post selected outlook contact items to an datagridview of an form:


        private void MoveSelectedContactToCRM()
        {
            Outlook.ApplicationClass app = new Outlook.ApplicationClass();
            Outlook.Selection selContacts = app.ActiveExplorer().Selection;

            MyTest.MyTestContactMoveToCRM ContactMoveToCRM = (MyTest.MyTestContactMoveToCRM)adxOlFormsCollectionItem4.GetForm(app.ActiveExplorer());
           
            ContactMoveToCRM.dtgSelectedAddresses.DataSource = null;

            DataTable dtSelectItems = new DataTable();
            dtSelectItems.Columns.Add("name", typeof(string));
            dtSelectItems.Columns.Add("vorname", typeof(string));
            dtSelectItems.Columns.Add("firma", typeof(string));
            dtSelectItems.Columns.Add("abteilung", typeof(string));
            dtSelectItems.Columns.Add("email", typeof(string));
            dtSelectItems.Columns.Add("mobile", typeof(string));
            dtSelectItems.Columns.Add("telefon", typeof(string));
            dtSelectItems.Columns.Add("user1", typeof(string));

            foreach (Outlook.ContactItem conItem in selContacts)
            {
                DataRow nRow = dtSelectItems.NewRow();
                nRow["name"] = conItem.LastName.ToString();
                nRow["vorname"] = conItem.FirstName;
                nRow["firma"] = conItem.CompanyName;
                nRow["abteilung"] = conItem.Department;
                nRow["email"] = conItem.Email1Address;
                nRow["mobile"] = conItem.MobileTelephoneNumber;
                nRow["telefon"] = conItem.BusinessTelephoneNumber;
                nRow["user1"] = conItem.User1;
                dtSelectItems.Rows.Add(nRow);
            }
            ContactMoveToCRM.dtgSelectedAddresses.DataSource = dtSelectItems;
            ContactMoveToCRM.dtgSelectedAddresses.Columns["name"].HeaderText = "Name";
            ContactMoveToCRM.dtgSelectedAddresses.Columns["vorname"].HeaderText = "Vorname";
            ContactMoveToCRM.dtgSelectedAddresses.Columns["firma"].HeaderText = "Firma";
            ContactMoveToCRM.dtgSelectedAddresses.Columns["abteilung"].HeaderText = "Abteilung";
            ContactMoveToCRM.dtgSelectedAddresses.Columns["email"].HeaderText = "e-Mail";
            ContactMoveToCRM.dtgSelectedAddresses.Columns["telefon"].HeaderText = "Telefon gesch.";
            ContactMoveToCRM.dtgSelectedAddresses.Columns["user1"].HeaderText = "ABW-ResNr";
        }


Best regards
Joachim Weber
Posted 20 May, 2015 05:22:11 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Thank you, Joachim!



Andrei Smolin
Add-in Express Team Leader
Posted 20 May, 2015 05:43:03 Top