Re: Accessing outlook form controls.

Tech-Archive recommends: Speed Up your PC by fixing your registry



You need to cast it to a control in the MS Forms 2.0 library, not to a Windows.Forms control. You should have a reference to that library so the properties, etc. of that ListBox are available to you.

The ListBox used in Outlook form controls doesn't have an Items collection, it has an AddItem method. All the items in the list are in the List collection. After adding that library reference use the Object Browser to see what's available to you for that control.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"MeAgin" <MeAgain@xxxxxxxxx> wrote in message news:uh1C1RbSHHA.2212@xxxxxxxxxxxxxxxxxxxxxxx
Hi Eric,

Thanks for the info.
In my VB.NET code initially I tried to get the object to a variable with the
ListBox type not Object type as mentioned. That was giving an error and when
I defined the variable as an Object it is working.
When I checked the type is shown that the type of this object is
"System.__ComObject" even it is a ListBox in the mail form.
Now I want to add some items to the ListBox and when I try to add items to
the Items collection like,

oControl.Items.Add("Item1")

It doesn't add and giving and error.
"Public member 'Items' on type 'Control' not found."

Then I tried to cast the object to a ListBox as
oListBox = CType(oControl, ListBox)
But it failec with the message,

"Unable to cast COM object of type 'System.__ComObject' to class type
'System.Windows.Forms.ListBox'. Instances of types that represent COM
components cannot be cast to types that do not represent COM components;
however they can be cast to interfaces as long as the underlying COM
component supports QueryInterface calls for the IID of the interface."

I understand the message but how can I cast the object as an interface. My
requiremnent is to add some items to a list box in a mail form from my com
add-in.

Thanks.
Nadee

.



Relevant Pages

  • Re: CButton casts
    ... >The pointer returned is usually cast to the type of control identified by ... >Microsfot's cast technique. ... pointer to the CWnd part of that object, which you can safely cast to the ...
    (microsoft.public.vc.mfc)
  • Re: Cannot convert type System.Web.UI.Control to ...
    ... Get its parent from the control and then cast it wil that. ... >>> I am trying to write some server side validator code in C#. ... >>> have a piece of code that can be used by all DropDownLists on a ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: "edit" control is read only?
    ... type casting every parameter in the SendMessage line, ... it, they did type cast every parameter, but it was only to show the type ... ReadOnly property to the edit control? ... Can anyone tell me why the edit control created with CreateWindow ...
    (microsoft.public.vc.language)
  • Re: Dynamically using object methods
    ... I can get the "SubjetObject" from objectToInspect.GetInfo, but can't figure out how to use that dynamically to cast objectToInspect. ... If you really do need to then you should ensure all objects that require this functionality implement an interface that contains the SetValueToNull ... Since I only have 3 types of objects at the moment, I could aways set up a switch statement using the result from GetType() and then cast each one. ... Since you don't have control over the classes, how were you expecting to get them to implement a SetValueToNull method in the first place? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: FAQ Related - why cast?
    ... To get the control you need ... consisting of a character, a 32-bit integer, and a 16-bit integer, from the ... and the cast to guards against sign extension. ... general, it's safer to use all unsigned types when writing code like this, ...
    (comp.lang.c)