Skip to main content

RepositoryItem.ParseEditValue Event

Converts an input value (entered by a user or assigned in code) to the value that the editor will store.

Namespace: DevExpress.XtraEditors.Repository

Assembly: DevExpress.XtraEditors.v24.2.dll

Declaration

[DXCategory("Events")]
public event ConvertEditValueEventHandler ParseEditValue

Event Data

The ParseEditValue event's data class is ConvertEditValueEventArgs. The following properties provide information specific to this event:

Property Description
Handled Gets or sets a value specifying whether default edit value conversion/formatting is required.
Value Gets or sets either the edit or the display value of an editor.

Remarks

Each time a user changes the value, or a new value is assigned to the editor in code, this value is converted to the appropriate type (numeric, date/time, etc.). The editor raises the ParseEditValue event. This event allows you to implement a custom edit value conversion.

The event’s e.Value parameter allows you to obtain the current edit value. Set this parameter to the value that the editor should store (standalone editors store the new value in the BaseEdit.EditValue property).

You must set the e.Handled property value to true to block the default conversion after your ParseEditValue event handler is complete.

Note

The ParseEditValue event may be called multiple times consecutively. The number of calls is different for different editor types and may also depend on the editor usage (standalone or embedded).

Read the following topic for additional information: Value Formatting.

The following example demonstrates how to convert the typed value into DateTime format.

using System;
using System.Collections.Generic;
using DevExpress.XtraEditors.Repository;

namespace DXApplication {
    public partial class Form1 : DevExpress.XtraEditors.XtraForm {
        public Form1() {
            InitializeComponent();
            gridControl1.DataSource = new List<DataObject>() {
                new DataObject { Date = DateTime.Now }
            };
        }

        private void Form1_Load(object sender, EventArgs e) {
            RepositoryItemTextEdit riTextEdit = new RepositoryItemTextEdit();
            riTextEdit.ParseEditValue += RiTextEdit_ParseEditValue;
            gridControl1.RepositoryItems.Add(riTextEdit);
            gridView1.Columns["Date"].ColumnEdit = riTextEdit;

        }

        private void RiTextEdit_ParseEditValue(object sender, DevExpress.XtraEditors.Controls.ConvertEditValueEventArgs e) {
            try {
                e.Value = Convert.ToDateTime(e.Value);
            } catch (FormatException ex) {
                e.Value = DateTime.Now;
            }
            e.Handled = true;
        }
    }
    public class DataObject {
        public DateTime Date { get; set; }
    }
}
See Also