[C#] DevExpress 피벗 그리드 컨트롤 사용하기 (WinForm Pivot grid)

손성권·2020년 11월 25일
0

PgmrNotes

목록 보기
1/1

피벗 그리드 컨트롤 가져오기

[도구 상자] - [Data & Analytics] 에서 PivotGridControl 을 끌어와 배치

피벗 그리드에 데이터 연결하기 (데이터베이스로 부터)

private void PivotGrid()

{

// 주어진 환경에 따라 데이터베이스 질의 결과를 테이터 셋(ds)으로 가지고 옵니다



pgcList.BeginUpdate();



pgcList.DataSource = ds.Tables[0];



// 행으로 나타낼 필드

PivotGridField fieldPV_CODE = new PivotGridField() 

{

    Area = PivotArea.RowArea,

    AreaIndex = 0,

    FieldName = "PV_CODE",

    Caption = "장비코드", 

};



// 열로 나타낼 필드

PivotGridField fieldPV_DATE = new PivotGridField()

{

    Area = PivotArea.ColumnArea,

    AreaIndex = 0,

    FieldName = "PV_DATE",

    Caption = "생산일자" 

};



// 데이터 필드

PivotGridField fieldPV_QTY = new PivotGridField()

{

    Area = PivotArea.DataArea,

    AreaIndex = 0,

    FieldName = "PV_QTY",

    Caption = "불량수량",

};

fieldPV_QTY.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric;

fieldPV_QTY.CellFormat.FormatString = "n0";



// 위에서 정의한 필드로 피벗 구성 

pgcList.Fields.Clear();

pgcList.Fields.AddRange(new PivotGridField[] {

                                  fieldPV_CODE, 

                                  fieldPV_DATE, 

                                  fieldPV_QTY 

                                 });

pgcList.EndUpdate();



// 필터 항목은 설정하지 않았으므로 숨김

pgcList.OptionsView.ShowFilterHeaders = false;

}

피벗 그리드와 차트 연결하기 (Binding Chart with Pivot grid)

- 해당 차트의 스마트 태그를 클릭

- 아래 그림과 같이 데이터 소스를 피벗 그리드 컨트롤로 설정

       ![](https://velog.velcdn.com/images%2Facronet%2Fpost%2F6ea742f1-98f5-4d6e-b24f-a5716a800841%2Fdev_Pivot2.jpg)

- 프로그램을 실행 피벗 그리드의 셀을 클릭하면 동적으로 그래프가 변경됨을 확인할 수 있다

[참고 사이트]

  1. 데브익스프레스 : Pivot Grid

    https://docs.devexpress.com/WindowsForms/3409/controls-and-libraries/pivot-grid

  1. 피벗 그리드 필드 생성 및 데이터 소스 연결하기

    https://docs.devexpress.com/WindowsForms/1921/controls-and-libraries/pivot-grid/examples/providing-data/how-to-bind-a-pivotgridcontrol-to-a-database

profile
코드는 끝나도록 공개해야 한다

0개의 댓글