IAccessible::get_accSelection method (oleacc.h)

The IAccessible::get_accSelection method retrieves the selected children of this object. All objects that support selection must support this property.


HRESULT get_accSelection(
  [out, retval] VARIANT *pvarChildren


[out, retval] pvarChildren


Address of a VARIANT structure that receives information about which children are selected. The following table describes the information returned in pvarChildren.

vt member Value member
No children are selected.
One child object is selected, and the address of its IDispatch interface is set in the pdispVal member.
lVal contains the child ID of the child element that is selected. If lVal is CHILDID_SELF, this means that the object itself is selected.
Multiple child objects are selected, and the punkVal member contains the address of the IUnknown interface. The client queries this interface for the IEnumVARIANT interface, which it uses to enumerate the selected objects.

Return value


If successful, returns S_OK.

If not successful, returns one of the values in the table that follows, or another standard COM error code. Servers return these values, but clients must always check output parameters to ensure that they contain valid values. For more information, see Checking IAccessible Return Values.

Error Description
The object does not support this property.


This method must support the IEnumVARIANT interface.

This method returns either an IDispatch interface pointer or a child ID for the pvarChildren parameter. For more information about how to use the IDispatch interface pointer or child ID, see How Child IDs Are Used in Parameters.

As with other IAccessible methods and functions, clients might receive errors for IAccessible interface pointers because of a user action. For more information, see Receiving Errors for IAccessible Interface Pointers.

Note:  This method retrieves a selected item, not selected text.

Server Example

The following example code shows a possible implementation of this method for a custom single-selection list box. Its GetSelectedIndex method returns -1 if no item is selected.

// m_pControl is the control that returns this accessible object. 

HRESULT STDMETHODCALLTYPE AccServer::get_accSelection(VARIANT *pvarChildren)
    int childID = m_pControl->GetSelectedIndex() + 1; // Convert from 0-based. 
    if (childID <= 0)
        pvarChildren->vt = VT_EMPTY;
        pvarChildren->vt = VT_I4;
        pvarChildren->lVal = childID;
    return S_OK;


Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header oleacc.h
Library Oleacc.lib
DLL Oleacc.dll
Redistributable Active Accessibility 1.3 RDK on Windows NT 4.0 with SP6 and later and Windows 95

See also





Selection and Focus Properties and Methods