Version

ColumnResizing Event

Occurs before a column is resized by the end user.
Syntax
'Declaration
 
Public Event ColumnResizing As ColumnResizingEventHandler
public event ColumnResizingEventHandler ColumnResizing
Event Data

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

PropertyDescription
Cancel (Inherited from System.ComponentModel.CancelEventArgs) 
Column (Inherited from Infragistics.Win.UltraWinListView.CancelableColumnEventArgs)Returns the UltraListViewColumnBase with which this instance is associated.
UIAction Returns the user interface action which triggered the firing of the event.
Remarks

The ColumnResizing event fires before the width of a column is changed through user interaction, either by dragging the right edge of the header, or, in the case where the AutoSizeMode property resolves to a value other than 'None', the header is double-clicked.

Example
The following code sample demonstrates how the UltraListView's ColumnResizing event can be handled to prevent a column from being resized, and how the ColumnResized event can be handled to auto-size all visible columns:

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.

Imports Infragistics.Win
Imports Infragistics.Win.UltraWinListView

    Private Sub ultraListView1_ColumnResizing(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinListView.ColumnResizingEventArgs) Handles ultraListView1.ColumnResizing

        '	If the column about to be resized is the MainColumn, cancel
        '	the event to prevent the column from being resized.
        If (e.Column.GetType() Is GetType(UltraListViewMainColumn)) Then e.Cancel = True
    End Sub

    Private Sub ultraListView1_ColumnResized(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinListView.ColumnResizedEventArgs) Handles ultraListView1.ColumnResized

        Dim listView As UltraListView = CType(sender, UltraListView)

        '	Get a rectangle which describes the client area
        '	of the control, so we can determine the width
        '	minus the width of the vertical scrollbar, if
        '	one is present.
        Dim displayRect As Rectangle = listView.DisplayRectangle
        Dim clientWidth As Integer = displayRect.Width

        '	Subtract out the width of the MainColumn
        Dim mainColumnWidth As Integer = IIf(listView.MainColumn.Width > 0, listView.MainColumn.Width, 200)
        clientWidth -= mainColumnWidth

        '	Iterate the SubItemColumns collection to get the number of
        '	visible columns.
        Dim visibleByDefault As Boolean = listView.ViewSettingsDetails.SubItemColumnsVisibleByDefault
        Dim visibleColumnsCount As Integer = 0
        Dim subItemColumn As UltraListViewSubItemColumn
        For Each subItemColumn In listView.SubItemColumns

            If (subItemColumn.VisibleInDetailsView = DefaultableBoolean.True Or _
                (visibleByDefault AndAlso subItemColumn.VisibleInDetailsView = DefaultableBoolean.Default)) Then
                visibleColumnsCount += 1
            End If

        Next

        '	Iterate the SubItemColumns collection and set the width
        For Each subItemColumn In listView.SubItemColumns
            subItemColumn.Width = Math.Floor((clientWidth / visibleColumnsCount))
        Next

    End Sub
using Infragistics.Win;
using Infragistics.Win.UltraWinListView;
using System.Diagnostics;

		private void ultraListView1_ColumnResizing(object sender, Infragistics.Win.UltraWinListView.ColumnResizingEventArgs e)
		{
			//	If the column about to be resized is the MainColumn, cancel
			//	the event to prevent the column from being resized.
			if ( e.Column is UltraListViewMainColumn )
				e.Cancel = true;
		}

		private void ultraListView1_ColumnResized(object sender, Infragistics.Win.UltraWinListView.ColumnResizedEventArgs e)
		{
			UltraListView listView = sender as UltraListView;

			//	Get a rectangle which describes the client area
			//	of the control, so we can determine the width
			//	minus the width of the vertical scrollbar, if
			//	one is present.
			Rectangle displayRect = listView.DisplayRectangle;
			int clientWidth = displayRect.Width;

			//	Subtract out the width of the MainColumn
			clientWidth -= listView.MainColumn.Width > 0 ? listView.MainColumn.Width : 200;

			//	Iterate the SubItemColumns collection to get the number of
			//	visible columns.
			bool visibleByDefault = listView.ViewSettingsDetails.SubItemColumnsVisibleByDefault;
			int visibleColumnsCount = 0;
			foreach( UltraListViewSubItemColumn subItemColumn in listView.SubItemColumns )
			{
				bool visible =	subItemColumn.VisibleInDetailsView == DefaultableBoolean.True ||
								(visibleByDefault && subItemColumn.VisibleInDetailsView == DefaultableBoolean.Default);

				if ( visible )
					visibleColumnsCount++;
			}

			//	Iterate the SubItemColumns collection and set the width
			foreach( UltraListViewSubItemColumn subItemColumn in listView.SubItemColumns )
			{
				subItemColumn.Width = (int)(clientWidth / visibleColumnsCount);
			}
		}
	}
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