Version

AutoSizeOptions Property

Returns or sets what values are considered when autosizing a field.
Syntax
'Declaration
 
Public Property AutoSizeOptions As Nullable(Of FieldAutoSizeOptions)
public Nullable<FieldAutoSizeOptions> AutoSizeOptions {get; set;}
Remarks

By default, this property will resolve to None and autosizing via the UI will be disabled. When set to some other value, the end user may double click on the far edge of a field label or cell to autosize the item based on the contents as specified by the value of this property.

Note: If AllowResize is resolved to false then the end user will not be able to resize the field using the auto size functionality.

Example
The following sample demonstrates setting the properties which determine what elements are considered when calculating the auto sized extent of a field.

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 fl As New FieldLayout()

        ' As with other properties on FieldSettings you can set 
        ' properties for a specific field layout that apply to 
        ' all fields in that field layout. 
        Dim flSettings As New FieldSettings()

        ' In this case, when autosizing we want to take into account 
        ' all records whether they are visible or not, in view or 
        ' not. Note, this adds overhead from a memory perspective 
        ' since all records must be loaded and from a processing 
        ' perspective since measuring the elements can take time 
        ' so you should use the default RecordsInView option when 
        ' possible especially when you have more than a small 
        ' # of records. 
        '
        flSettings.AutoSizeScope = FieldAutoSizeScope.AllRecords

        ' The AutoSizeOptions indicates the types of elements that 
        ' you want to measure. In this case we will default to auto 
        ' sizing to the label and data cells only (ignoring filter 
        ' cells and summaries). Usually this will be left to the 
        ' default value of All.
        flSettings.AutoSizeOptions = FieldAutoSizeOptions.Label Or FieldAutoSizeOptions.DataCells

        fl.FieldSettings = flSettings

        ' Auto indicates that the size of the field should grow as 
        ' larger data is encountered (scrolling, adding records, 
        ' editing cell data, etc.).
        Dim fEmail As New Field()
        fEmail.Name = "email"
        fEmail.Width = FieldLength.Auto

        ' You can set the properties on a per field basis. For this 
        ' field since each record has a unique value and therefore 
        ' we could have lots of different values to measure, we'll 
        ' just auto size to what's in view.
        Dim fs As New FieldSettings()
        fs.AutoSizeScope = FieldAutoSizeScope.RecordsInView
        fEmail.Settings = fs

        fl.Fields.Add(fEmail)


        ' InitialAuto indicates that the size of the field should be 
        ' based upon the initial content when the field layout is 
        ' first used.
        Dim fDept As New Field()
        fDept.Name = "department"
        fDept.Width = FieldLength.InitialAuto

        ' The AutoSizeOptions and Scope are used to determine what to 
        ' measure initially as well as when the user double clicks on 
        ' the field edge.
        fs = New FieldSettings()
        fs.AutoSizeScope = FieldAutoSizeScope.AllRecords
        fs.AutoSizeOptions = FieldAutoSizeOptions.All
        fDept.Settings = fs
        fl.Fields.Add(fDept)



        ' explicit logical pixel width
        Dim fName As New Field()
        fName.Name = "name"
        fName.Width = New FieldLength(150)

        ' The AutoSizeOptions and AutoSizeScope affect fields that are 
        ' not explicitly autosized as well. They are used to determine 
        ' what is measured when the end-user double clicks on the far 
        ' edge of a field label/cell.
        fs = New FieldSettings()
        fs.AutoSizeScope = FieldAutoSizeScope.RecordsInView
        fName.Settings = fs
        fl.Fields.Add(fName)


        Dim uf1 As New UnboundField()
        uf1.Name = "IsActive"
        uf1.Width = FieldLength.InitialAuto
        uf1.DataType = GetType(Boolean)

        ' If you do use an AutoSizeScope of AllRecords, you still may 
        ' want to set this to RecordsInView for fields where the extent 
        ' of the data doesn't change based on the value (e.g. a 
        ' checkbox field).
        fs = New FieldSettings()
        fs.AutoSizeScope = FieldAutoSizeScope.RecordsInView
        fs.AutoSizeOptions = FieldAutoSizeOptions.All
        uf1.Settings = fs
        fl.Fields.Add(uf1)

        ' add the new field layout we define to the datapresenter
        grid.FieldLayouts.Add(fl)
    End Sub
using Infragistics.Windows.DataPresenter;


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

	private void InitializeControl(XamDataGrid grid)
	{
		FieldLayout fl = new FieldLayout();

        // As with other properties on FieldSettings you can set 
		// properties for a specific field layout that apply to 
		// all fields in that field layout. 
		FieldSettings flSettings = new FieldSettings();

		// In this case, when autosizing we want to take into account 
		// all records whether they are visible or not, in view or 
		// not. Note, this adds overhead from a memory perspective 
		// since all records must be loaded and from a processing 
		// perspective since measuring the elements can take time 
		// so you should use the default RecordsInView option when 
		// possible especially when you have more than a small 
		// # of records. 
		//
		flSettings.AutoSizeScope = FieldAutoSizeScope.AllRecords;

		// The AutoSizeOptions indicates the types of elements that 
		// you want to measure. In this case we will default to auto 
		// sizing to the label and data cells only (ignoring filter 
		// cells and summaries). Usually this will be left to the 
		// default value of All.
		flSettings.AutoSizeOptions = FieldAutoSizeOptions.Label | FieldAutoSizeOptions.DataCells;

		fl.FieldSettings = flSettings;

		// Auto indicates that the size of the field should grow as 
		// larger data is encountered (scrolling, adding records, 
		// editing cell data, etc.).
		Field fEmail = new Field();
		fEmail.Name = "email";
		fEmail.Width = FieldLength.Auto;

		// You can set the properties on a per field basis. For this 
		// field since each record has a unique value and therefore 
		// we could have lots of different values to measure, we'll 
		// just auto size to what's in view.
		FieldSettings fs = new FieldSettings();
		fs.AutoSizeScope = FieldAutoSizeScope.RecordsInView;
		fEmail.Settings = fs;

		fl.Fields.Add(fEmail);


		// InitialAuto indicates that the size of the field should be 
		// based upon the initial content when the field layout is 
		// first used.
		Field fDept = new Field();
		fDept.Name = "department";
		fDept.Width = FieldLength.InitialAuto;

		// The AutoSizeOptions and Scope are used to determine what to 
		// measure initially as well as when the user double clicks on 
		// the field edge.
		fs = new FieldSettings();
		fs.AutoSizeScope = FieldAutoSizeScope.AllRecords;
		fs.AutoSizeOptions = FieldAutoSizeOptions.All;
		fDept.Settings = fs;
		fl.Fields.Add(fDept);



		// explicit logical pixel width
		Field fName = new Field();
		fName.Name = "name";
		fName.Width = new FieldLength(150);

		// The AutoSizeOptions and AutoSizeScope affect fields that are 
		// not explicitly autosized as well. They are used to determine 
		// what is measured when the end-user double clicks on the far 
		// edge of a field label/cell.
		fs = new FieldSettings();
		fs.AutoSizeScope = FieldAutoSizeScope.RecordsInView;
		fName.Settings = fs;
		fl.Fields.Add(fName);


		UnboundField uf1 = new UnboundField();
		uf1.Name = "IsActive";
		uf1.Width = FieldLength.InitialAuto;
		uf1.DataType = typeof(bool);

		// If you do use an AutoSizeScope of AllRecords, you still may 
		// want to set this to RecordsInView for fields where the extent 
		// of the data doesn't change based on the value (e.g. a 
		// checkbox field).
		fs = new FieldSettings();
		fs.AutoSizeScope = FieldAutoSizeScope.RecordsInView;
		fs.AutoSizeOptions = FieldAutoSizeOptions.All;
		uf1.Settings = fs;
		fl.Fields.Add(uf1);

		// add the new field layout we define to the datapresenter
		grid.FieldLayouts.Add(fl);
	}
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:igDP="http://infragistics.com/DataPresenter"

<igDP:XamDataGrid BindToSampleData="True">
    
<igDP:XamDataGrid.FieldLayouts>
        
<igDP:FieldLayout>
            
<igDP:FieldLayout.FieldSettings>
                
<!-- As with other properties on FieldSettings 
                    you can set properties for a specific 
                    field layout that apply to all fields in 
                    that field layout. 
                
                    In this case, when autosizing we want to take 
                    into account all records whether they are 
                    visible or not, in view or not. Note, this 
                    adds overhead from a memory perspective since 
                    all records must be loaded and from a 
                    processing perspective since measuring the 
                    elements can take time so you should use the 
                    default RecordsInView option when possible 
                    especially when you have more than a small 
                    # of records. 
                
                    The AutoSizeOptions indicates the types of 
                    elements that you want to measure. In this 
                    case we will default to auto sizing to the 
                    label and data cells only (ignoring filter 
                    cells and summaries). Usually this will be 
                    left to the default value of All. 
-->
                
<igDP:FieldSettings 
                    
AutoSizeOptions="Label, DataCells"
                    
AutoSizeScope="AllRecords" />
            
</igDP:FieldLayout.FieldSettings>
            
            
<!-- Auto indicates that the size of the field should 
                grow as larger data is encountered (scrolling, 
                adding records, editing cell data, etc.).
-->
            
<igDP:Field Name="email" Width="Auto">
                
<igDP:Field.Settings>
                    
<!-- You can set the properties on a per field basis.
                        For this field since each record has a unique 
                        value and therefore we could have lots of 
                        different values to measure, we'll just auto size 
                        to what's in view.
                        
-->
                    
<igDP:FieldSettings AutoSizeScope="RecordsInView" />
                
</igDP:Field.Settings>
            
</igDP:Field>
            
            
<!-- InitialAuto indicates that the size of the field 
                should be based upon the initial content when the 
                field layout is first used. 
-->
            
<igDP:Field Name="department" Width="InitialAuto">
                
<igDP:Field.Settings>
                    
<!-- The AutoSizeOptions and Scope are used to 
                        determine what to measure initially as well as 
                        when the user double clicks on the field edge. 
-->
                    
<igDP:FieldSettings AutoSizeOptions="All" 
                            
AutoSizeScope="AllRecords" />
                
</igDP:Field.Settings>
            
</igDP:Field>

            
<igDP:Field Name="name" Width="150">
                
<igDP:Field.Settings>
                    
<!-- The AutoSizeOptions and AutoSizeScope affect 
                        fields that are not explicitly autosized as 
                        well. They are used to determine what is 
                        measured when the end-user double clicks on 
                        the far edge of a field label/cell. 
-->
                    
<igDP:FieldSettings AutoSizeScope="RecordsInView" />
                
</igDP:Field.Settings>
            
</igDP:Field>

            
<igDP:UnboundField 
                
Name="IsActive" 
                
DataType="{x:Type sys:Boolean}" 
                
Width="InitialAuto">
                
<igDP:Field.Settings>
                    
<!-- If you do use an AutoSizeScope of AllRecords, you 
                        still may want to set this to RecordsInView for 
                        fields where the extent of the data doesn't change 
                        based on the value (e.g. a checkbox field). 
-->
                    
<igDP:FieldSettings AutoSizeOptions="All" 
                            
AutoSizeScope="RecordsInView" />
                
</igDP:Field.Settings>
            
</igDP:UnboundField>
        
</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