■ DataControlBase 클래스의 AutoGeneratedColumns 이벤트를 사용해 데이터 바인딩 시 모든 컬럼이 생성된 후 처리하는 방법을 보여준다.
▶ 예제 코드 (XAML)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<Window x:Class="HowToCustomizeAutomaticallyGeneratedColumns.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:HowToCustomizeAutomaticallyGeneratedColumns" Title="Customize Automatically Generated Columns" Width="600" Height="450"> <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> |
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
#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 |