■ TableView 클래스 : 데이터 주석 특성을 사용해 검증하기

----------------------------------------------------------------------------------------------------

Employee.cs

 

 

using System.ComponentModel.DataAnnotations;

 

namespace HowToImplementAttributesBasedValidation

{

    /// <summary>

    /// 직원

    /// </summary>

    public class Employee

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Property

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region ID - ID

 

        /// <summary>

        /// ID

        /// </summary>

        public int ID { get; set; }

 

        #endregion

 

        #region 상급자 ID - ParentID

 

        /// <summary>

        /// 상급자 ID

        /// </summary>

        public int ParentID { get; set; }

 

        #endregion

 

        #region 성명 - Name

 

        /// <summary>

        /// 성명

        /// </summary>

        [Required(AllowEmptyStrings = false, ErrorMessage = "The Name cannot be empty. Please correct.")]

        public string Name { get; set; }

 

        #endregion

 

        #region 직위 - Position

 

        /// <summary>

        /// 직위

        /// </summary>

        [StringLength(20)]

        public string Position { get; set; }

 

        #endregion

 

        #region 부서 - Department

 

        /// <summary>

        /// 부서

        /// </summary>

        [Required(AllowEmptyStrings = false, ErrorMessage = "The Department cannot be empty. Please correct.")]

        public string Department { get; set; }

 

        #endregion

    }

}

 

 

MainPage.xaml

 

 

<Window

    x:Class="HowToImplementAttributesBasedValidation.MainWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"

    Width="600"

    Height="450"

    Title="Implement Attributes-Based Validation">

    <Grid>

        <dxg:GridControl Name="gridControl" >

            <dxg:GridControl.Columns>

                <dxg:GridColumn FieldName="Name"       />

                <dxg:GridColumn FieldName="Position"   />

                <dxg:GridColumn FieldName="Department" />

            </dxg:GridControl.Columns>

            <dxg:GridControl.View>

                <dxg:TableView Name="tableView"

                    ShowValidationAttributeErrors="True"

                    AllowCommitOnValidationAttributeError="False" />

            </dxg:GridControl.View>

        </dxg:GridControl>

    </Grid>

</Window>

 

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요