Version

Width Property

Gets/sets the width of this UltraListViewColumnBase, expressed in pixels.
Syntax
'Declaration
 
Public Property Width As Integer
public int Width {get; set;}
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