Skip to main content

DataFormView.GetValue(String) Method

Returns the current value of a Data Form editor by the name of the property to which the editor is bound.

Namespace: DevExpress.Maui.DataForm

Assembly: DevExpress.Maui.Editors.dll

NuGet Package: DevExpress.Maui.Editors

Declaration

public object GetValue(
    string propertyName
)

Parameters

Name Type Description
propertyName String

The name of the property to which the Data Form editor is bound.

Returns

Type Description
System.Object

The current editor value.

Remarks

The following example obtains the editor value on a button’s tap:

<ContentPage ...
             xmlns:dxdf="clr-namespace:DevExpress.Maui.DataForm;assembly=DevExpress.Maui.Editors"
             xmlns:dx="clr-namespace:DevExpress.Maui.Core;assembly=DevExpress.Maui.Core">
    <Grid RowDefinitions="*,50" ColumnDefinitions="*,*">
        <dxdf:DataFormView x:Name="dataForm" Grid.Row="0" Grid.ColumnSpan="2" 
                            EditorLabelWidth="95" CommitMode="LostFocus">
        </dxdf:DataFormView>
        <dx:DXButton Clicked="Button_Clicked" Content="Get Value" 
                        WidthRequest="160" Grid.Row="1" Grid.Column="1"/>
    </Grid>
</ContentPage>
using DevExpress.Maui.DataForm;
using System.Collections;

namespace ComboBoxEditor {

    public partial class MainPage : ContentPage {
        public MainPage() {
            InitializeComponent();
            dataForm.DataObject = new EmployeeInfo();
            dataForm.PickerSourceProvider = new ComboBoxDataProvider();
        }

        private void Button_Clicked(object sender, EventArgs e) {
            var dfEditorValue = dataForm.GetValue("Department");
            // Add your custom logic here.
        }
    }
}
Show Data Source
using DevExpress.Maui.DataForm;
using System.Collections;
namespace ComboBoxEditor {
    public class EmployeeInfo {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        [DataFormComboBoxEditor(ValueMember = "DepartmentCode", DisplayMember = "DepartmentName")]
        [DataFormDisplayOptions(HelpText = "Select a department", LabelPosition = DataFormLabelPosition.Top)]
        public int Department { get; set; }
        [DataFormComboBoxEditor]
        public string Status { get; set; }
    }
    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 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;
        }
    }
}

You can also call a specific Data Form editor’s GetValue() method to set the current value.

Call the Data Form editor DataFormItem.SetValue(Object) method to set the value in the edit box. Before you call the SetValue method, ensure the DataFormView.DataObject property source implements the INotifyPropertyChanged interface.

See Also