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

TypeDescription
Long A long expression that indicates the width of the column to fit the entire column's content.

Use the AutoWidth property to arrange the columns to fit the entire control's content. The AutoWidth property doesn't change the column's width. Use Width property to change the column's width at runtime. Use the ColumnAutoResize property to specify whether the control resizes all visible columns to fit the control's client area.

The following VB function resizes all columns:

Private Sub autoSize(ByVal t As EXG2ANTTLibCtl.G2antt)
    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( CG2antt& g2antt )
{
	g2antt.BeginUpdate();
	CColumns columns = g2antt.GetColumns();
	for ( long i = 0;i < columns.GetCount(); i++ )
	{
		CColumn column = columns.GetItem( COleVariant( i ) );
		if ( column.GetVisible() )
			column.SetWidth( column.GetAutoWidth() );
	}
	g2antt.EndUpdate();
}

The following VB.NET sample resizes all visible columns:

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

The following C# sample resizes all visible columns:

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

The following VFP sample resizes all visible columns:

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