■ DataGridControl 엘리먼트에서 언바운드 데이터를 제공하는 방법을 보여준다.
▶ 예제 코드 (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 31 32 33 34 35 36 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid" xmlns:local="clr-namespace:TestProject" Width="600" Height="450" Title="언바운드 데이터 제공하기"> <Window.Resources> <xcdg:DataGridCollectionViewSource x:Key="DataGridCollectionViewSourceKey" Source="{Binding Source={x:Static Application.Current}, Path=ProductTable}"> <xcdg:DataGridCollectionViewSource.ItemProperties> <xcdg:DataGridUnboundItemProperty Name="TotalUnitValue" DataType="{x:Type s:Double}" QueryValue="totalUnitValueDataGridUnboundItemProperty_QueryValue" /> </xcdg:DataGridCollectionViewSource.ItemProperties> </xcdg:DataGridCollectionViewSource> <local:CurrencyConverter x:Key="CurrencyConverterKey"/> </Window.Resources> <Grid> <xcdg:DataGridControl x:Name="dataGridControl" ItemsSource="{Binding Source={StaticResource DataGridCollectionViewSourceKey}}"> <xcdg:DataGridControl.Columns> <xcdg:Column FieldName="TotalUnitValue" Title="Total Inventory"> <xcdg:Column.CellContentTemplate> <DataTemplate> <TextBlock Text="{Binding Converter={StaticResource CurrencyConverterKey}}" /> </DataTemplate> </xcdg:Column.CellContentTemplate> </xcdg:Column> <xcdg:Column FieldName="Photo" Visible="False" /> </xcdg:DataGridControl.Columns> </xcdg:DataGridControl> </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 |
using System; using System.Data; using Xceed.Wpf.DataGrid; #region Total Unit Value 데이터 그리드 언바운드 항목 속성 값 질의시 처리하기 - totalUnitValueDataGridUnboundItemProperty_QueryValue(sender, e) /// <summary> /// Total Unit Value 데이터 그리드 언바운드 항목 속성 값 질의시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void totalUnitValueDataGridUnboundItemProperty_QueryValue(object sender, DataGridItemPropertyQueryValueEventArgs e) { DataRowView dataRowView = e.Item as DataRowView; if(dataRowView != null ) { if(dataRowView["UnitsInStock"] != DBNull.Value) { e.Value = (double)((short)dataRowView["UnitsInStock"] * (decimal)dataRowView["UnitPrice"]); } } } #endregion |
※ 전체 실행 가능한 코드가 아닌 일부 발췌된 코드이다.