Version

ExpandedStateChanging Event

Fires before the control has expanded or collapsed. You can prevent the expanded state from changing by setting the Cancel property of the event argument to true.
Syntax
'Declaration
 
Public Event ExpandedStateChanging As CancelEventHandler
public event CancelEventHandler ExpandedStateChanging
Event Data

The event handler receives an argument of type CancelEventArgs containing data related to this event. The following CancelEventArgs properties provide information specific to this event.

PropertyDescription
Cancel  
Remarks
Handle the ExpandedStateChanging event to cancel a change to the control's expanded state. Handle the ExpandedStateChanged event to execute code immediately after the value of the Expanded property has changed.
Example
This snippet demonstrates how the ExpandedStateChanging event can be used to prevent the user from altering the expanded state of the UltraExpandableGroupBox. This can be useful in situations where you want to ensure that the data in the contained controls is valid, but cannot use their Validating events due to performance reasons (ex. a remote database determines if the values are valid, etc.).

For an overview of how to handle events in Visual Basic or Visual C#, see Event Handlers in Visual Basic and Visual C#. For specific information and code examples illustrating how to consume events in your application, see Consuming Events in the .NET Framework Developer's Guide.

Private Sub UltraExpandableGroupBox1_ExpandedStateChanging(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles UltraExpandableGroupBox1.ExpandedStateChanging

    ' If the control is in the process of expanding, then just return.
    If Not Me.UltraExpandableGroupBox1.Expanded Then
        Return
    End If
    ' If the input values of the UltraExpandableGroupBox's contained controls
    ' are invalid, prevent the control from collapsing.
    If Not Me.IsInputValid Then
        e.Cancel = True
    End If

End Sub

Private ReadOnly Property IsInputValid() As Boolean
    Get
        Dim isValid As Boolean = True

        ' Perform processing, such as attempting to update a database, 
        ' to determine if the values in the controls in the
        ' UltraExpandableGroupBox are valid...

        Return isValid
    End Get
End Property
private void ultraExpandableGroupBox1_ExpandedStateChanging(object sender, System.ComponentModel.CancelEventArgs e)
{
	// If the control is in the process of expanding, then just return.
	if( ! this.ultraExpandableGroupBox1.Expanded )
		return;

	// If the input values of the UltraExpandableGroupBox's contained controls
	// are invalid, prevent the control from collapsing.
	if( ! this.IsInputValid )
		e.Cancel = true;
}

private bool IsInputValid
{
	get
	{
		bool isValid = true;

		// Perform processing, such as attempting to update a database, 
		// to determine if the values in the controls in the
		// UltraExpandableGroupBox are valid...

		return isValid;
	}
}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also