첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

728x90
반응형

TestProject.zip
다운로드

▶ MainWindow.xaml

<Window x:Class="TestProject.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"
    xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
    xmlns:local="clr-namespace:TestProject"
    Width="800"
    Height="600"
    Title="자동으로 생성된 컬럼 커스텀 처리하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Window.Resources>
        <local:IssueTypeToSolidColorBrushValueConverter x:Key="IssueTypeToSolidColorBrushValueConverterKey" />
        <DataTemplate x:Key="IssueTypeDataTemplateKey">
            <dxe:TextEdit x:Name="PART_Editor"
                Foreground="{Binding Path=Value, Converter={StaticResource IssueTypeToSolidColorBrushValueConverterKey}}" />
        </DataTemplate>
    </Window.Resources>
    <Grid>
       <dxg:GridControl x:Name="gridControl"
        AutoGenerateColumns="AddNew"
        AutoGeneratedColumns="gridControl_AutoGeneratedColumns">
          <dxg:GridControl.View>
             <dxg:TableView Name="tableView"
                AutoWidth="True" />
          </dxg:GridControl.View>
       </dxg:GridControl>
    </Grid>
</Window>

 

▶ MainWindow.xaml.cs

using System.Windows;
using System.Windows.Markup;

using DevExpress.Data;
using DevExpress.Xpf.Grid;

namespace TestProject
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public partial class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            this.gridControl.ItemsSource = new IssueList().GetData();
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 그리드 컨트롤 자동 생성 컬럼 처리하기 - gridControl_AutoGeneratedColumns(sender, e)

        /// <summary>
        /// 그리드 컨트롤 자동 생성 컬럼 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void gridControl_AutoGeneratedColumns(object sender, RoutedEventArgs e)
        {
            foreach(GridColumn gridColumn in this.gridControl.Columns)
            {
                if(gridColumn.FieldName == "IssueName")
                {
                    string cellTemplate = @"
<DataTemplate
    xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
    xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
    xmlns:dxe=""http://schemas.devexpress.com/winfx/2008/xaml/editors"">
    <dxe:TextEdit x:Name=""PART_Editor"" Foreground=""Blue"" />
</DataTemplate>";

                    gridColumn.CellTemplate = XamlReader.Parse(cellTemplate) as DataTemplate;
                    gridColumn.SortOrder    = ColumnSortOrder.Ascending;
                }
                else if(gridColumn.FieldName == "IssueType")
                {
                    gridColumn.CellTemplate = Application.Current.MainWindow.Resources["IssueTypeDataTemplateKey"] as DataTemplate;
                }
                else if(gridColumn.FieldName == "ID")
                {
                    gridColumn.Visible = false;
                }
            }
        }

        #endregion
    }
}
728x90
반응형
Posted by 사용자 icodebroker

댓글을 달아 주세요