Version

AutoFitMode Property

Returns or sets a value indicating which fields should be resized when AutoFit is enabled.
Syntax
'Declaration
 
Public Property AutoFitMode As AutoFitMode
public AutoFitMode AutoFitMode {get; set;}
Example
The following sample demonstrates the various modes in which the DataPresenter can resize the fields based on the area available. Note, in these samples the Key property of the layout has been set to allow defining multiple FieldLayouts with the same structure. Remove the Key for the field layout whose layout you want to see when using the sample code.

Imports Infragistics.Windows.DataPresenter

    Private Sub xamDataGrid1_Initialized(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.InitializeControl(DirectCast(sender, XamDataGrid))
    End Sub

    Private Sub InitializeControl(ByVal grid As XamDataGrid)
        Dim f As Field = Nothing

        ' You can control the default AutoFitMode for all FieldLayouts 
        ' that haven't explicitly set their AutoFitMode by either 
        ' setting it on the DP's FieldLayoutSettings. You can also 
        ' set the previously existing AutoFit property on the 
        ' DataPresenterBase.
        Dim flDefaultSettings As New FieldLayoutSettings()
        flDefaultSettings.AutoFitMode = AutoFitMode.Never
        flDefaultSettings.HeaderPrefixAreaDisplayMode = HeaderPrefixAreaDisplayMode.FieldChooserButton
        grid.FieldLayoutSettings = flDefaultSettings


        ' OnlyWithVisibleStarFields
        ' =========================

        ' AutoFitMode of OnlyWithVisibleStarFields so as long as there are 
        ' star fields visible, the fields will fill the available area.
        Dim flStar As New FieldLayout()
        flStar.Key = "HasStarFields"
        Dim flStarSettings As New FieldLayoutSettings()
        flStarSettings.AutoFitMode = AutoFitMode.OnlyWithVisibleStarFields
        flStar.Settings = flStarSettings

        f = New Field()
        f.Name = "name"
        flStar.Fields.Add(f)

        f = New Field()
        f.Name = "salary"
        flStar.Fields.Add(f)

        f = New Field()
        f.Name = "email"
        f.Width = New FieldLength(1, FieldLengthUnitType.Star)
        flStar.Fields.Add(f)

        f = New Field()
        f.Name = "department"
        f.Width = New FieldLength(2, FieldLengthUnitType.Star)
        flStar.Fields.Add(f)

        ' Always
        ' ======

        ' AutoFitMode of Always means all visible fields are resized to fill the 
        ' available area. The extent of fields may be increased or decreased.
        Dim flAlways As New FieldLayout()
        flAlways.Key = "Always"
        Dim flAlwaysSettings As New FieldLayoutSettings()
        flAlwaysSettings.AutoFitMode = AutoFitMode.Always
        flAlways.Settings = flAlwaysSettings

        f = New Field()
        f.Name = "name"
        flAlways.Fields.Add(f)

        f = New Field()
        f.Name = "salary"
        flAlways.Fields.Add(f)

        f = New Field()
        f.Name = "email"
        flAlways.Fields.Add(f)

        f = New Field()
        f.Name = "department"
        flAlways.Fields.Add(f)

        ' ExtendLastField
        ' ===============
        ' AutoFitMode of ExtendLastField is a little different than the 
        ' other modes in that non-star fields will never be reduced. The 
        ' preferred sizes of the fields is used and if there is extra 
        ' space available the last field will be increased in width to 
        ' fill the available area.
        Dim flExtend As New FieldLayout()
        flExtend.Key = "ExtendLastField"
        Dim flExtendSettings As New FieldLayoutSettings()
        flExtendSettings.AutoFitMode = AutoFitMode.ExtendLastField
        flExtend.Settings = flExtendSettings

        f = New Field()
        f.Name = "name"
        flExtend.Fields.Add(f)

        f = New Field()
        f.Name = "salary"
        flExtend.Fields.Add(f)

        f = New Field()
        f.Name = "email"
        flExtend.Fields.Add(f)

        f = New Field()
        f.Name = "department"
        flExtend.Fields.Add(f)

        ' Remove the key of one of these to use it in the sample
        ' e.g.
        'flStar.Key = Nothing

        grid.FieldLayouts.Add(flStar)
        grid.FieldLayouts.Add(flAlways)
        grid.FieldLayouts.Add(flExtend)
    End Sub
using Infragistics.Windows.DataPresenter;

	private void xamDataGrid1_Initialized(object sender, EventArgs e)
	{
		this.InitializeControl(sender as XamDataGrid);
	}

	private void InitializeControl(XamDataGrid grid)
	{
		Field f = null;

		// You can control the default AutoFitMode for all FieldLayouts 
		// that haven't explicitly set their AutoFitMode by either 
		// setting it on the DP's FieldLayoutSettings. You can also 
		// set the previously existing AutoFit property on the 
		// DataPresenterBase.
		FieldLayoutSettings flDefaultSettings = new FieldLayoutSettings();
		flDefaultSettings.AutoFitMode = AutoFitMode.Never;
		flDefaultSettings.HeaderPrefixAreaDisplayMode = HeaderPrefixAreaDisplayMode.FieldChooserButton;
		grid.FieldLayoutSettings = flDefaultSettings;


		// OnlyWithVisibleStarFields
		// =========================

		// AutoFitMode of OnlyWithVisibleStarFields so as long as there are 
		// star fields visible, the fields will fill the available area.
		FieldLayout flStar = new FieldLayout();
		flStar.Key = "HasStarFields";
		FieldLayoutSettings flStarSettings = new FieldLayoutSettings();
		flStarSettings.AutoFitMode = AutoFitMode.OnlyWithVisibleStarFields;
		flStar.Settings = flStarSettings;

		f = new Field();
		f.Name = "name";
		flStar.Fields.Add(f);

		f = new Field();
		f.Name = "salary";
		flStar.Fields.Add(f);

		f = new Field();
		f.Name = "email";
		f.Width = new FieldLength(1, FieldLengthUnitType.Star);
		flStar.Fields.Add(f);

		f = new Field();
		f.Name = "department";
		f.Width = new FieldLength(2, FieldLengthUnitType.Star);
		flStar.Fields.Add(f);

		// Always
		// ======

		// AutoFitMode of Always means all visible fields are resized to fill the 
		// available area. The extent of fields may be increased or decreased.
		FieldLayout flAlways = new FieldLayout();
		flAlways.Key = "Always";
		FieldLayoutSettings flAlwaysSettings = new FieldLayoutSettings();
		flAlwaysSettings.AutoFitMode = AutoFitMode.Always;
		flAlways.Settings = flAlwaysSettings;

		f = new Field();
		f.Name = "name";
		flAlways.Fields.Add(f);

		f = new Field();
		f.Name = "salary";
		flAlways.Fields.Add(f);

		f = new Field();
		f.Name = "email";
		flAlways.Fields.Add(f);

		f = new Field();
		f.Name = "department";
		flAlways.Fields.Add(f);

		// ExtendLastField
		// ===============
		// AutoFitMode of ExtendLastField is a little different than the 
		// other modes in that non-star fields will never be reduced. The 
		// preferred sizes of the fields is used and if there is extra 
		// space available the last field will be increased in width to 
		// fill the available area.
		FieldLayout flExtend = new FieldLayout();
		flExtend.Key = "ExtendLastField";
		FieldLayoutSettings flExtendSettings = new FieldLayoutSettings();
		flExtendSettings.AutoFitMode = AutoFitMode.ExtendLastField;
		flExtend.Settings = flExtendSettings;

		f = new Field();
		f.Name = "name";
		flExtend.Fields.Add(f);

		f = new Field();
		f.Name = "salary";
		flExtend.Fields.Add(f);

		f = new Field();
		f.Name = "email";
		flExtend.Fields.Add(f);

		f = new Field();
		f.Name = "department";
		flExtend.Fields.Add(f);

		// Remove the key of one of these to use it in the sample
		// e.g.
		//flExtend.Key = null;

		grid.FieldLayouts.Add(flStar);
		grid.FieldLayouts.Add(flAlways);
		grid.FieldLayouts.Add(flExtend);
	}
xmlns:igDP="http://infragistics.com/DataPresenter"

    
<igDP:XamDataGrid BindToSampleData="True">
        
<igDP:XamDataGrid.FieldLayoutSettings>
            
<!-- You can control the default AutoFitMode for 
                all FieldLayouts that haven't explicitly set their 
                AutoFitMode by either setting it on the DP's   
                FieldLayoutSettings. You can also set the previously 
                existing AutoFit property on the DataPresenterBase.
-->
            
<igDP:FieldLayoutSettings 
                
AutoFitMode="Never"
                
HeaderPrefixAreaDisplayMode="FieldChooserButton" 
                
/>
        
</igDP:XamDataGrid.FieldLayoutSettings>

        
<!-- Remove the key of one of these to use it in the sample -->
        
<igDP:XamDataGrid.FieldLayouts>
            
<!-- AutoFitMode of OnlyWithVisibleStarFields so as long as there are 
                star fields visible, the fields will fill the available area. 
-->
            
<igDP:FieldLayout Key="HasStarFields">
                
<igDP:Field Name="name" />
                
<igDP:Field Name="salary" />
                
<igDP:Field Name="email" Width="*" />
                
<igDP:Field Name="department" Width="2*" />

                
<igDP:FieldLayout.Settings>
                    
<igDP:FieldLayoutSettings AutoFitMode="OnlyWithVisibleStarFields" />
                
</igDP:FieldLayout.Settings>
            
</igDP:FieldLayout>

            
<!-- AutoFitMode of Always means all visible fields are resized to fill 
                the available area. The extent of fields may be increased or 
                decreased. 
-->
            
<igDP:FieldLayout Key="Always">
                
<igDP:Field Name="name" />
                
<igDP:Field Name="salary" />
                
<igDP:Field Name="email" />
                
<igDP:Field Name="department" />
                
                
<igDP:FieldLayout.Settings>
                    
<igDP:FieldLayoutSettings AutoFitMode="Always" />
                
</igDP:FieldLayout.Settings>
            
</igDP:FieldLayout>

            
<!-- AutoFitMode of ExtendLastField is a little different than the 
                other modes in that non-star fields will never be reduced. The 
                preferred sizes of the fields is used and if there is extra 
                space available the last field will be increased in width to 
                fill the available area. 
-->
            
<igDP:FieldLayout Key="ExtendLastField">
                
<igDP:Field Name="name" />
                
<igDP:Field Name="salary" />
                
<igDP:Field Name="email" />
                
<igDP:Field Name="department" Width="*" />

                
<igDP:FieldLayout.Settings>
                    
<igDP:FieldLayoutSettings AutoFitMode="ExtendLastField" />
                
</igDP:FieldLayout.Settings>
            
</igDP:FieldLayout>
        
</igDP:XamDataGrid.FieldLayouts>
    
</igDP:XamDataGrid>
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, 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