Back to Devexpress

RepositoryItem.ParseEditValue Event

windowsforms-devexpress-dot-xtraeditors-dot-repository-dot-repositoryitem-de52a403.md

latest6.6 KB
Original Source

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.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Events")]
public event ConvertEditValueEventHandler ParseEditValue
vb
<DXCategory("Events")>
Public Event ParseEditValue As ConvertEditValueEventHandler

Event Data

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

PropertyDescription
HandledGets or sets a value specifying whether default edit value conversion/formatting is required.
ValueGets 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.

csharp
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; }
    }
}
vb
Imports DevExpress.XtraEditors.Controls
Imports DevExpress.XtraEditors.Repository

Partial Public Class Form1
    Public Sub New()
        InitializeComponent()
        GridControl1.DataSource = New List(Of DataObject)() From {
            New DataObject With {.Date = Date.Now}
        }
    End Sub

    Private Sub RiTextEdit_ParseEditValue(ByVal sender As Object, ByVal e As ConvertEditValueEventArgs)
        Try
            e.Value = Convert.ToDateTime(e.Value)
        Catch ex As FormatException
            e.Value = Date.Now
        End Try
        e.Handled = True
    End Sub

    Private Sub Form1_Load_1(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim riTextEdit As New RepositoryItemTextEdit()
        AddHandler riTextEdit.ParseEditValue, AddressOf RiTextEdit_ParseEditValue
        GridControl1.RepositoryItems.Add(riTextEdit)
        GridView1.Columns("Date").ColumnEdit = riTextEdit
    End Sub
End Class

Public Class DataObject
    Public Property Date As Date
End Class

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ParseEditValue event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

xaf-how-to-display-an-enumeration-property-as-a-drop-down-box-with-check-boxes/CS/EFCore/EnumCheckBoxEF/EnumCheckBoxEF.Win/Editors/EnumPropertyEditorEx.cs#L50

csharp
checkedItem.EndUpdate();
checkedItem.ParseEditValue += checkedEdit_ParseEditValue;
checkedItem.CustomDisplayText += checkedItem_CustomDisplayText;

See Also

FormatEditValue

Format and Parse Editor Values

RepositoryItem Class

RepositoryItem Members

DevExpress.XtraEditors.Repository Namespace