첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170

▶ MainApplication.xaml

<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>

 

728x90

 

▶ MainApplication.xaml.cs

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
    }
}

 

300x250

 

▶ MainWindow.xaml

<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>
    <Grid>
        <xcdg:DataGridControl x:Name="dataGridControl"
            ItemsSource="{Binding Source={StaticResource DataGridCollectionViewSourceKey}}">
            <xcdg:DataGridControl.Columns>
                <xcdg:Column FieldName="Freight">
                    <xcdg:Column.CellEditor>
                        <xcdg:CellEditor>
                            <xcdg:CellEditor.EditTemplate>
                                <DataTemplate>
                                    <DockPanel>
                                        <TextBlock x:Name="actual_value"
                                            DockPanel.Dock="Top"
                                            Text="{xcdg:CellEditorBinding}" />
                                        <UniformGrid x:Name="parentPanel"
                                            DockPanel.Dock="Top"
                                            Columns="4"
                                            Tag="{Binding ElementName=actual_value, Path=Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                            Button.Click="button_Click">
                                            <Button x:Name="sevenButton"
                                                Content="7" />
                                            <!-- ... -->
                                            <Button x:Name="additionButton"
                                                Content="+" />
                                        </UniformGrid>
                                        <TextBlock x:Name="currentEquationTextBlock"
                                            DockPanel.Dock="Bottom" />
                                    </DockPanel>
                                </DataTemplate>
                            </xcdg:CellEditor.EditTemplate>
                            <xcdg:CellEditor.ActivationGestures>
                                <xcdg:KeyActivationGesture Key="NumPad0" />
                                <!-- ... -->
                                <xcdg:KeyActivationGesture Key="NumPad9" />
                            </xcdg:CellEditor.ActivationGestures>
                        </xcdg:CellEditor>
                    </xcdg:Column.CellEditor>
                </xcdg:Column>
            </xcdg:DataGridControl.Columns>
        </xcdg:DataGridControl>
    </Grid>
</Window>

 

▶ MainWindow.xaml.cs

using System.Windows;

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

        #region 생성자 - MainWindow()

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

        #endregion

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

        #region 버튼 클릭시 처리하기 - button_Click(sender, e)

        /// <summary>
        /// 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void button_Click(object sender, RoutedEventArgs e)
        {
            // ...
        }

        #endregion
    }
}

※ MS Access 파일 처리를 위해 플랫폼 대상을 x86으로 컴파일해야 한다.

※ 전체 실행 가능한 코드가 아닌 일부 발췌된 코드이다.

728x90
반응형
그리드형(광고전용)
Posted by 사용자 icodebroker
TAG , , ,

댓글을 달아 주세요