DevExpress/개발

DevExpress GridColumn DateTime Format 설정

푸코잇 2024. 1. 9. 08:48
728x90
<dxg:GridControl ItemsSource="{Binding ItemCollection}">
    <dxg:GridControl.View>
        <dxg:TableView ShowGroupPanel="False"/>
    </dxg:GridControl.View>

    <dxg:GridColumn FieldName="LastUpdateTime" Header="최종 업데이트 날짜" Width="150"/>
</dxg:GridControl>

 

DevExpress에서 GirdColumn에 DateTime을 바인딩한 경우 기본적으로 "yyyy-MM-dd" Format으로 표시된다.

시, 분, 초 등 Format을 변경하고 싶으면 Mask를 이용하면 된다.

 

GridColumn DateTime Format 설정

 

GridColumn의 스마트 태그를 통해 Mask를 설정할 수 있다.

우선 GridColumn의 EditSettings 속성을 지정해야 한다.

DateTime을 위한 DateEditSettings를 지정하면 된다.

이후 자신이 원하는 Mask를 설정하면 된다.

 

 

 

<dx:ThemedWindow x:Class="DateTimeFormat.MainWindow"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
                 xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
                 xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:vm="clr-namespace:DateTimeFormat"
                 Title="DateTimeFormat" Height="350" Width="525">
    <dx:ThemedWindow.DataContext>
        <vm:MainWindowVM/>
    </dx:ThemedWindow.DataContext>

    <Grid>
        <dxg:GridControl ItemsSource="{Binding ItemCollection}">
            <dxg:GridControl.View>
                <dxg:TableView ShowGroupPanel="False"/>
            </dxg:GridControl.View>

            <dxg:GridColumn FieldName="LastUpdateTime" Header="최종 업데이트 날짜" Width="150">
                <!--DateTime Format 설정-->
                <dxg:GridColumn.EditSettings>
                    <dxe:DateEditSettings MaskType="DateTime" Mask="G" MaskUseAsDisplayFormat="True"/>
                </dxg:GridColumn.EditSettings>
            </dxg:GridColumn>
        </dxg:GridControl>
    </Grid>
</dx:ThemedWindow>

 

아마 스마트 태그로 Mask 설정을 한 후 실행하면 적용이 안될 수 있다.

그렇다면 MaskUseAsDisplayFormt을 True로 설정하자.

이는 편집기에 포커스가 없을 때에도 Mask를 사용하여 표시 값의 형식이 계속 지정되는지 여부이다.

 

  • GridColumn DateTime Format 적용결과