This documentation is archived and is not being maintained.

StructureChangedEventArgs Constructor

Initializes a new instance of the StructureChangeType class, specifying the type of change and the identifier (ID) of the element whose structure changed.

Namespace:  System.Windows.Automation
Assembly:  UIAutomationTypes (in UIAutomationTypes.dll)

public StructureChangedEventArgs(
	StructureChangeType structureChangeType,
	int[] runtimeId
)

Parameters

structureChangeType
Type: System.Windows.Automation.StructureChangeType

A single value that specifies the type of change.

runtimeId
Type: System.Int32[]

The runtime identifier (ID) of the UI Automation element whose structure changed. See Remarks.

The values that can be returned in structureChangeType depend on the implementation of the UI Automation provider. For example, when items are added to or removed from a Win32 list box, if the provider is not able to determine the number of items added or removed, it might specify ChildrenInvalidated and not ChildAdded or ChildRemoved.

The following table describes the information in the event received by the StructureChangedEventHandler for different structure changes.

structureChangeType

Event source

runtimeId

ChildAdded

The child that was added.

The child that was added.

ChildRemoved

The parent of the child that was removed.

The child that was removed.

ChildrenBulkAdded

The parent of the children that were added.

The parent of the children that were added.

ChildrenBulkRemoved

The parent of the children that were removed.

The parent of the children that were removed.

ChildrenInvalidated

The parent of the children that were invalidated.

The parent of the children that were invalidated

Custom controls might not be able to provide a meaningful value in runtimeId. For more information, see RaiseStructureChangedEvent.

The following example shows how to construct and raise an event when children are added to, or removed from, a custom list box.

/// <summary> 
/// Responds to an addition to the UI Automation tree structure by raising an event. 
/// </summary> 
/// <param name="list">
/// The list to which the item was added. 
/// </param> 
/// <remarks> 
/// For the runtime Id of the item, pass 0 because the provider cannot know 
/// what its actual runtime Id is. 
/// </remarks> 
public static void OnStructureChangeAdd(CustomListControl list)
{
    if (AutomationInteropProvider.ClientsAreListening)
    {
        int[] fakeRuntimeId = { 0 };
        StructureChangedEventArgs args =
            new StructureChangedEventArgs(StructureChangeType.ChildrenBulkAdded, 
            fakeRuntimeId);
        AutomationInteropProvider.RaiseStructureChangedEvent(
            (IRawElementProviderSimple)list.Provider, args);
    }
}

/// <summary> 
/// Responds to a removal from the UI Automation tree structure  
/// by raising an event. 
/// </summary> 
/// <param name="list">
/// The list from which the item was removed. 
/// </param> 
/// <remarks> 
/// For the runtime Id of the list, pass 0 because the provider cannot know 
/// what its actual runtime ID is. 
/// </remarks> 
public static void OnStructureChangeRemove(CustomListControl list)
{
    if (AutomationInteropProvider.ClientsAreListening)
    {
        int[] fakeRuntimeId = { 0 };
        StructureChangedEventArgs args =
            new StructureChangedEventArgs(StructureChangeType.ChildrenBulkRemoved, 
            fakeRuntimeId);
        AutomationInteropProvider.RaiseStructureChangedEvent(
            (IRawElementProviderSimple)list.Provider, args);
    }
}

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Show: