첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

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:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid"
    Width="800"
    Height="600"
    Title="프로그램적으로 MS 액세스 데이터베이스에 피벗 그리드 바인딩 하기"
    FontFamily="나눔고딕코딩"
    FontSize="16"
    Loaded="Window_Loaded">
    <Grid>
        <dxpg:PivotGridControl x:Name="pivotGridControl" />
    </Grid>
</Window>

 

728x90

 

▶ MainWindow.xaml.cs

using System.Data;
using System.Data.OleDb;
using System.Windows;

using DevExpress.Xpf.PivotGrid;

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

        #region 생성자 - MainWindow()

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

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region 윈도우 로드시 처리하기 - Window_Loaded(sender, e)

        /// <summary>
        /// 윈도우 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            OleDbConnection  oleDbConnection  = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND.MDB");
            OleDbDataAdapter oleDbDataAdapter = new OleDbDataAdapter("SELECT * FROM SalesPerson", oleDbConnection);
            DataSet          dataSet          = new DataSet();

            oleDbDataAdapter.Fill(dataSet, "SalesPerson");

            this.pivotGridControl.DataSource = dataSet.Tables["SalesPerson"];

            this.pivotGridControl.BeginUpdate();

            #region Country 필드

            PivotGridField countryPivotGridField = new PivotGridField("Country", FieldArea.RowArea);

            countryPivotGridField.AreaIndex = 0;

            #endregion
            #region Customer 필드

            PivotGridField customerPivotGridField = new PivotGridField("Sales Person", FieldArea.RowArea);

            customerPivotGridField.AreaIndex = 1;
            customerPivotGridField.Caption   = "Customer";

            #endregion
            #region Product Category 필드

            PivotGridField productCategoryPivotGridField = new PivotGridField("CategoryName", FieldArea.ColumnArea);

            productCategoryPivotGridField.AreaIndex = 0;
            productCategoryPivotGridField.Caption   = "Product Category";

            #endregion
            #region Year 필드

            PivotGridField yearPivotGridField = new PivotGridField("OrderDate", FieldArea.ColumnArea);

            yearPivotGridField.AreaIndex     = 1;
            yearPivotGridField.GroupInterval = FieldGroupInterval.DateYear;
            yearPivotGridField.Caption       = "Year";

            #endregion
            #region Product Name 필드

            PivotGridField productNamePivotGridField = new PivotGridField("ProductName", FieldArea.FilterArea);

            productNamePivotGridField.Caption = "Product Name";

            #endregion
            #region Extended Price 필드

            PivotGridField extendedPricePivotGridField = new PivotGridField("Extended Price", FieldArea.DataArea);

            extendedPricePivotGridField.CellFormat = "c0";

            #endregion

            this.pivotGridControl.Fields.AddRange
            (
                countryPivotGridField        ,
                customerPivotGridField       ,
                productCategoryPivotGridField,
                yearPivotGridField           ,
                productNamePivotGridField    ,
                extendedPricePivotGridField
            );

            this.pivotGridControl.EndUpdate();
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요