property Column.AutoWidth as Long
Computes the column's width required to fit the entire column's content.

TypeDescription
Long A long value that indicates the required width of the column to fit the entire column's content.
The AutoWidth property ensures that the width of the control is adjusted to accommodate the complete content of all columns. To ensure that all columns within the control are arranged to accommodate its entire content, you can use the AutoWidth property. This property adjusts the layout of the columns to fit the content of the control without modifying the actual widths of individual columns. It essentially redistributes the available space among the columns without altering their predefined widths. Use the Width property to actually change the column's width at runtime. The ColumnAutoResize property allows you to determine whether the control should automatically resize all visible columns to fit within the control's client area. When enabled, this ensures that the columns adjust their widths dynamically to utilize the available space efficiently, eliminating any unused or overflowing areas.

The following VB function resizes all columns:

Private Sub autoSize(ByVal t As EXGRIDLibCtl.Grid)
    t.BeginUpdate
        Dim c As Column
        For Each c In t.Columns
            c.Width = c.AutoWidth
        Next
        t.EndUpdate
        t.Refresh
End Sub

The following C++ sample resizes all visible columns:

#include "Columns.h"
#include "Column.h"
void autoSize( CGrid& grid )
{
	grid.BeginUpdate();
	CColumns columns = grid.GetColumns();
	for ( long i = 0;i < columns.GetCount(); i++ )
	{
		CColumn column = columns.GetItem( COleVariant( i ) );
		if ( column.GetVisible() )
			column.SetWidth( column.GetAutoWidth() );
	}
	grid.EndUpdate();
}

The following VB.NET sample resizes all visible columns:

Private Sub autoSize(ByRef grid As AxEXGRIDLib.AxGrid)
    grid.BeginUpdate()
    Dim i As Integer
    With grid.Columns
        For i = 0 To .Count - 1
            If .Item(i).Visible Then
                .Item(i).Width = .Item(i).AutoWidth
            End If
        Next
    End With
    grid.EndUpdate()
End Sub

The following C# sample resizes all visible columns:

private void autoSize( ref AxEXGRIDLib.AxGrid grid )
{
	grid.BeginUpdate();
	for ( int i = 0; i < grid.Columns.Count - 1; i++ )
		if ( grid.Columns[i].Visible) 
			grid.Columns[i].Width = grid.Columns[i].AutoWidth;
	grid.EndUpdate();
}

The following VFP sample resizes all visible columns:

with thisform.Grid1
	.BeginUpdate()
	for i = 0 to .Columns.Count - 1
		if ( .Columns(i).Visible )
			.Columns(i).Width = .Columns(i).AutoWidth
		endif
	next
	.EndUpdate()
endwith