DxComboBox<TData, TValue>.EditFormat Property
Specifies the pattern used to format an editor’s value.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v23.1.dll
NuGet Package: DevExpress.Blazor
Declaration
[Parameter]
public string EditFormat { get; set; }
Property Value
Type | Description |
---|---|
String | The format pattern. |
Remarks
Use the EditFormat
property to format an editor’s value when the editor is focused.
Note
To format the ComboBox’s display value when the editor is not focused, use the DisplayFormat property. If you do not specify the DisplayFormat
property, the EditFormat
also applies to the editor value when the editor is not focused.
The EditFormat
property allows you to format values displayed in one-column and multi-column ComboBoxes.
Format a One-Column ComboBox
The code below applies the following formats to the ComboBox editor:
- The currency format to numeric display values.
- The fixed-point format to numeric edit values.
<DxComboBox Data="@Prices"
@bind-Value="@CurrentPrice"
EditFormat="F"
DisplayFormat="C">
</DxComboBox>
@code {
IEnumerable<string> Prices = new List<string>() {
"20.5",
"25",
"50",
};
string CurrentPrice { get; set; }
}
Format a Multi-Column ComboBox
The code below adds three columns to a ComboBox and applies the {1} {2}
format to the component’s edit values. This format specifies that the editor value includes values of the Name (VisibleIndex = 1
) and Surname (VisibleIndex = 2
) columns.
Note
When you enable filter mode for a multi-column ComboBox, the filter only takes into account data of the columns that are used in the editor’s format pattern.
<DxComboBox Data="@Staff.DataSource"
@bind-Value="@SelectedPerson"
EditFormat ="{1} {2}">
<Columns>
<DxListEditorColumn FieldName="Id" Width="50px" />
<DxListEditorColumn FieldName="FirstName" Caption="Name"/>
<DxListEditorColumn FieldName="LastName" Caption="Surname"/>
</Columns>
</DxComboBox>
@code {
Person SelectedPerson { get; set; } = Staff.DataSource[0];
}
Format ComboBox Bound to a Custom-Type Collection
If you bind the ComboBox to a custom-type collection, you set the TextFieldName property. This property specifies the custom object’s field name that returns strings for the ComboBox’s drop-down window. The EditFormat
is applied to these field values.
If the TextFieldName
property is not specified, the ComboBox component searches for a Text field in the data source and uses this field as a text field. Otherwise, ComboBox populates its items with the CustomType.ToString()
values. In these cases, the EditFormat
is applied to these values.
<DxComboBox Data="@Data"
@bind-Value="@CurrentID"
EditFormat="d"
TextFieldName="@nameof(Model.DateTimeValue)"
ValueFieldName="@nameof(Model.ID)">
</DxComboBox>
@code {
public class Model {
public DateTime DateTimeValue { get; set; }
public int ID { get; set; }
}
int CurrentID { get; set; }
List<Model> Data;
protected override void OnInitialized() {
Data = new() {
new() { DateTimeValue = DateTime.Today.AddDays(-1), ID = 0 },
new() { DateTimeValue = DateTime.Today, ID = 1 },
new() { DateTimeValue = DateTime.Today.AddDays(1), ID = 2 },
new() { DateTimeValue = DateTime.Today.AddDays(2), ID = 3 }
};
}
}