Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

DataFormItem.SetValue(Object) Method

Specifies the Data Form editor value.

Namespace: DevExpress.Maui.DataForm

Assembly: DevExpress.Maui.Editors.dll

NuGet Package: DevExpress.Maui.Editors

#Declaration

C#
public virtual void SetValue(
    object newValue
)

#Parameters

Name Type Description
newValue System.Object

A value to be assigned to the editor.

#Remarks

Before you call the SetValue method, ensure the DataFormView.DataObject property source implements the INotifyPropertyChanged interface.

Use the following methods to obtain a data form editor’s value:

#Example

The following example fills in a Data Form when a user taps the button:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:dxdf="clr-namespace:DevExpress.Maui.DataForm;assembly=DevExpress.Maui.Editors"
             xmlns:dx="clr-namespace:DevExpress.Maui.Core;assembly=DevExpress.Maui.Core"
             xmlns:local="clr-namespace:ComboBoxEditor"
             x:Class="ComboBoxEditor.MainPage">
    <ScrollView>
        <StackLayout>
            <dxdf:DataFormView x:Name="dataForm" 
                               EditorLabelWidth="95" >
                <dxdf:DataFormView.DataObject>
                    <local:EmployeeInfo/>
                </dxdf:DataFormView.DataObject>
                <dxdf:DataFormView.PickerSourceProvider>
                    <local:ComboBoxDataProvider/>
                </dxdf:DataFormView.PickerSourceProvider>
                <dxdf:DataFormView.Items>
                    <dxdf:DataFormTextItem x:Name="firstNameEditor" 
                                           FieldName="FirstName" />
                    <dxdf:DataFormTextItem x:Name="lastNameEditor" 
                                           FieldName="LastName"/>
                    <dxdf:DataFormComboBoxItem x:Name="departmentEditor" 
                                               FieldName="Department" 
                                               ValueMember = "DepartmentCode"
                                               DisplayMember = "DepartmentName"/>
                    <dxdf:DataFormComboBoxItem x:Name="statusEditor"
                                               FieldName="Status" 
                                               LabelText="Status Value" />
                </dxdf:DataFormView.Items>
            </dxdf:DataFormView>
            <dx:DXButton Clicked="Button_Clicked" Content="Fill in the Form" WidthRequest="200"/>
        </StackLayout>
    </ScrollView>
</ContentPage>
using DevExpress.Maui.DataForm;
using System.Collections;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace ComboBoxEditor {

    public partial class MainPage : ContentPage {
        public MainPage() {
            InitializeComponent();
        }
        private void Button_Clicked(object sender, EventArgs e) {
            firstNameEditor.SetValue("Anne");
            lastNameEditor.SetValue("Dodsworth");
            departmentEditor.SetValue(2);
            statusEditor.SetValue("Salaried");
        }
    }

    public class EmployeeInfo: INotifyPropertyChanged {
        string firstName = "";
        public string FirstName {
            get { return firstName; }
            set { firstName = value; OnPropertyChanged("FirstName"); }
        }
        string lastName = "";
        public string LastName {
            get { return lastName; }
            set { lastName = value; OnPropertyChanged("LastName"); }
        }
        int? department = null;
        public int? Department {
            get { return department; }
            set { department = value; OnPropertyChanged("Department"); }
        }
        string status = "";
        public string Status {
            get { return status; }
            set { status = value; OnPropertyChanged("Status"); }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged([CallerMemberName] string propertyName = "") {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

    }
    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;
        }
    }
}
See Also