Accessing Properties from one adxOlForm to the other

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

Accessing Properties from one adxOlForm to the other
 
Patrick Jox




Posts: 83
Joined: 2009-05-09
Hello,
I have an Outlook form with four adxOlForm items each displayed in inspector region. In one form there is a GUI to adminstrate a list of unit items. These Items shall be used on a second form to populate a comboboy (for lookup).

"Units" is a public property of first form. How can I access it from the second one?

Kind regards
Patrick
Posted 05 Aug, 2009 15:10:32 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hello Patrick,

Please visit the HOWTOs page at our web site. It contains a useful sample add-in projects. It is a good start point for you.

BTW Please have a look at the Items property of the form manager.
.NET, Extended MAPI, Windows Phone & RT
Posted 06 Aug, 2009 07:19:47 Top
Fedor Shihantsov


Add-in Express team


Posts: 1188
Joined: 2005-01-11
Hello Patrick,

Use the adxOlFormsCollectionItem.FormInstanceCount prperty and the adxOlFormsCollectionItem.FormInstances(i) method.

Say, in the following way: (adxOlFormsCollectionItem.FormInstances(i) as MyAdxOlForm).Units
Posted 07 Aug, 2009 09:57:31 Top
Patrick Jox




Posts: 83
Joined: 2009-05-09
Sounds good. But where do I get the adxOlFormsCollectionItem from?

As far as I see, the addinModule exists as single instance in the whole application and so there is one singel formsmanager too which has an items collection. But where / how can I access the real instances of a form.

Maybe I am blind or it's because of the sunday?

Kind regards
Patrick
Posted 09 Aug, 2009 14:25:38 Top
Patrick Jox




Posts: 83
Joined: 2009-05-09
OK. I found the adyOlFormsCollectionItem in my addinModule. So using the IdentifyTheForm-Sample I can find the current index of the active form. Normally this should be the same index in the other form I want to access.

Is this the way I have to work?

Sounds a bit complicated and not really sure? Is this a good way?

Kind regards
Patrick
Posted 09 Aug, 2009 14:51:45 Top
Fedor Shihantsov


Add-in Express team


Posts: 1188
Joined: 2005-01-11
Patrick,

I do not recommend you using the same index. Use the sample solution.
You can compare ADXOlForm.CurrentOutlookWindowHandle properties instead of using the same index.
Posted 10 Aug, 2009 08:24:02 Top
Patrick Jox




Posts: 83
Joined: 2009-05-09
But how can I access form1 (which is currently not shown) from within form2 (which is currently active / visible). the currentOutlookWindowHandle will be the one of form2 so how should I recognize the good instance of form1?

Regards
Patrick
Posted 10 Aug, 2009 09:46:08 Top
Fedor Shihantsov


Add-in Express team


Posts: 1188
Joined: 2005-01-11
Please see the code below from the
"How to use several forms in one advanced form region" howto.


        public AddinExpress.OL.ADXOlForm InactiveForm()
        {
            for (int i = 0; i < adxOlFormsCollectionItem1.FormInstanceCount; i++)
            {
                if (adxOlFormsCollectionItem1.FormInstances(i).Visible
                    && !adxOlFormsCollectionItem1.FormInstances(i).Active)
                {
                    return adxOlFormsCollectionItem1.FormInstances(i);
                }
            }

            for (int i = 0; i < adxOlFormsCollectionItem2.FormInstanceCount; i++)
            {
                if (adxOlFormsCollectionItem2.FormInstances(i).Visible
                    && !adxOlFormsCollectionItem2.FormInstances(i).Active)
                {
                    return adxOlFormsCollectionItem2.FormInstances(i);
                }
            }

            return null;
        }


Please let me know if you have other questions or if my answers were not sufficient for you.
Posted 10 Aug, 2009 10:26:03 Top
Patrick Jox




Posts: 83
Joined: 2009-05-09
Sorry I do not really see the advantage of this.

You iterate through the FormInstances and return the first one which ist visible but not active. But how can I find out that this is the one of my currently visible outlook item?

Since adxOlFormsCollectionItem is hosted in the add-in there is no reference to the outlook item that instanced the form.

Oh this brings me to the idea to enhance the forms to have a property for the Outlook.ContactItem.EntryId which could be set during OnLoad of the form.

I will give it a trial.

Kind regards
Patrick
Posted 11 Aug, 2009 13:13:16 Top
Fedor Shihantsov


Add-in Express team


Posts: 1188
Joined: 2005-01-11
Well, assume you have two adxOlFormsCollectionItems. ADXOlForm1 corresponds to adxOlFormsCollectionItem1. ADXOlForm2 corresponds to adxOlFormsCollectionItem2.
Currently ADXOlForm2 shows up in an Inspector. It is visible and active.
ADXOlForm1 shows up in an Inspector, it is visible but not active (I.e. it is located under ADXOlForm2).

Task: Need to find ADXOlForm1 in the same Inspector where ADXOlForm2 is located.

Solution:


//ADXOlForm2 code
public void Test()
{
    ADXOlForm1 form = (this.AddinModule as AddinModule).FindForm(this.CurrentOutlookWindowHandle);
}

//AddinModule Code
public ADXOlForm1 FindForm(IntPtr CurrentOutlookWindowHandle) 
        { 
            for (int i = 0; i &lt; adxOlFormsCollectionItem1.FormInstanceCount; i++) 
            { 
                if (adxOlFormsCollectionItem1.FormInstances(i).Visible 
                    && !adxOlFormsCollectionItem1.FormInstances(i).Active
                    && CurrentOutlookWindowHandle == adxOlFormsCollectionItem1.FormInstances(i).CurrentOutlookWindowHandle
) 
                { 
                    return adxOlFormsCollectionItem1.FormInstances(i) as ADXOlForm1 ; 
                } 
            } 
            return null; 
        } 



Will that do?
Posted 12 Aug, 2009 08:49:20 Top