maui-devexpress-dot-maui-dot-dataform-dot-dataformcomboboxeditorattribute.md
Gets or sets the name of the data source field whose values are displayed as drop-down list items.
Namespace : DevExpress.Maui.DataForm
Assembly : DevExpress.Maui.Editors.dll
NuGet Package : DevExpress.Maui.Editors
public string DisplayMember { get; set; }
| Type | Description |
|---|---|
| String |
A field name in a data source.
|
DataFormView generates ComboBoxEdit editors for the underlying data object’s properties of the enum type. You can also bind a combo box editor to a collection that stores objects of any type - for example, primitive types (strings, integers, etc.) or custom objects.
To specify an item source for the data form’s combo box editor, follow the steps below:
Department
The data provider’s GetSource method returns a list of DepartmentInfo objects that serve as the data source for the drop-down item list of the Department combo box. Use the ValueMember and DisplayMember parameters to specify data source field names that supply item values (integer values that define department codes) and display strings (department names), respectively.
Status
The data provider’s GetSource method returns a list of strings that are displayed as items within the Status combo box and used to set the data object’s Status property value.
using Microsoft.Maui.Controls;
using System.Collections;
using System.Collections.Generic;
using DevExpress.Maui.DataForm;
namespace DataForm_ComboBoxEditor {
public class DepartmentInfo {
public int DepartmentCode { get; set; }
public string DepartmentName { get; set; }
public DepartmentInfo(int code, string name) {
DepartmentCode = code;
DepartmentName = name;
}
}
public class EmployeeInfo {
public string FirstName { get; set; }
public string LastName { get; set; }
[DataFormComboBoxEditor(ValueMember = "DepartmentCode", DisplayMember = "DepartmentName")]
public int Department { get; set; }
[DataFormComboBoxEditor]
public string Status { get; set; }
}
public class ComboBoxDataProvider : IPickerSourceProvider {
public IEnumerable GetSource(string propertyName) {
if (propertyName == "Department") {
return new List<DepartmentInfo>() {
new DepartmentInfo(0, "Sales"),
new DepartmentInfo(1, "Support"),
new DepartmentInfo(2, "Shipping"),
new DepartmentInfo(3, "Engineering"),
new DepartmentInfo(4, "Human Resources"),
new DepartmentInfo(5, "Management"),
new DepartmentInfo(6, "IT")
};
}
if (propertyName == "Status") {
return new List<string>() {
"Salaried",
"Commission",
"Terminated",
"On Leave"
};
}
return null;
}
}
public partial class MainPage : ContentPage {
public MainPage() {
InitializeComponent();
dataForm.DataObject = new EmployeeInfo();
dataForm.PickerSourceProvider = new ComboBoxDataProvider();
}
}
}
See Also
DataFormComboBoxEditorAttribute Class