■ DataGridControl 엘리먼트에서 현재 항목에서 값을 구하는 방법을 보여준다.
▶ MainApplication.xaml
1 2 3 4 5 6 7 8 |
<Application x:Class="TestProject.MainApplication" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> |
▶ MainApplication.xaml.cs
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
using System; using System.Data; using System.Data.OleDb; using System.Windows; namespace TestProject { /// <summary> /// 메인 애플리케이션 /// </summary> public partial class MainApplication : Application { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 주문 테이블 /// </summary> private static DataTable _orderTable; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 주문 테이블 - OrderTable /// <summary> /// 주문 테이블 /// </summary> public static DataTable OrderTable { get { return _orderTable; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Static #region 생성자 - MainApplication() /// <summary> /// 생성자 /// </summary> static MainApplication() { DataSet dataSet = new DataSet(); string filePath = @"c:\DS.Core\DS.Test.SampleDatabase\nwind.mdb"; string connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", filePath); OleDbConnection oleDbConnection = new OleDbConnection(connectionString); OleDbDataAdapter oleDbDataAdapter = new OleDbDataAdapter(); oleDbDataAdapter.SelectCommand = new OleDbCommand("SELECT * FROM Orders", oleDbConnection); oleDbDataAdapter.Fill(dataSet, "Orders"); _orderTable = dataSet.Tables["Orders"]; } #endregion } } |
▶ MainWindow.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 |
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid" x:Class="TestProject.MainWindow" Width="600" Height="450" Title="현재 항목에서 값 구하기"> <Window.Resources> <xcdg:DataGridCollectionViewSource x:Key="DataGridCollectionViewSourceKey" Source="{Binding Source={x:Static Application.Current}, Path=OrderTable}" /> </Window.Resources> <DockPanel Margin="5"> <StackPanel Margin="0 0 0 5" DockPanel.Dock="Top" Orientation="Horizontal"> <TextBlock Text="{Binding ElementName=dataGridControl, Path=CurrentItem[ShipCountry]}" /> <TextBlock Text=" - " /> <TextBlock Text="{Binding ElementName=dataGridControl, Path=CurrentItem[ShipCity]}" /> </StackPanel> <xcdg:DataGridControl x:Name="dataGridControl" ItemsSource="{Binding Source={StaticResource DataGridCollectionViewSourceKey}}" /> </DockPanel> </Window> |
▶ MainWindow.xaml.cs
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 |
using System.Windows; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); } #endregion } } |
※ MS Access 파일 처리를 위해 플랫폼 대상을 x86으로 컴파일해야 한다.