[C# DevExpress] 윈폼 DevExpress GridControl(그리드컨트롤)에서 Column, Row(컬럼,로우) 폰트 변경 및 ColumnHeader 가운데 정렬 하는 방법


안녕하세요.

 

오늘은 윈폼 DevExpress에서 제공해주는 컨트롤인 GridControl(그리드 컨트롤)에 대해서 알아 보려고 합니다.

 

그 중에서, Column, Row 폰트 변경 및 ColumnHeader 가운데 정렬 하는 방법을

알려 드리려고 해요.

 

그럼 바로 예제 프로젝트를 만들어서 어떻게 폰트를 변경하고 가운데 정렬을 하는지 보도록 할게요.


 

먼저, 빈폼 프로젝트를 생성해 주시고 아래와 같이 GridControl을 배치해 주시기 바랍니다.


윈폼 프로젝트 생성 및 GridControl 배치



위와 같이 그리드 컨트롤을 배치 완료 하셨다면, 이제 소스 코드 창으로 가셔서 예제 코드를 작성해 보도록 하겠습니다.


예제 코드


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

74

75

76

77

using DevExpress.Spreadsheet;

using DevExpress.Utils;

using DevExpress.XtraEditors.Repository;

using DevExpress.XtraGrid.Views.Grid;

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

 

namespace DevTest

{

    public partial class Form1 : DevExpress.XtraEditors.XtraForm

    {

        public Form1()

        {

            InitializeComponent();

 

            // Shown 이벤트 선언

            this.Shown += DevForm_Shown;

        }

 

        /// <summary>

        /// 폼이 보여질 일어나는 이벤트 핸들러

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        public void DevForm_Shown(object sender, EventArgs e)

        {

            uiView_Main.OptionsView.ShowGroupPanel = false;

            uiView_Main.OptionsBehavior.Editable = true;

 

            this.uiView_Main.Columns.Clear();

 

            DataTable dt = new DataTable();

            dt = GetData();

 

            //Grid 데이터 넣기

            uiGrid_Main.DataSource = dt;

 

            //Column, Row 폰트 사이즈종류 변경

            uiView_Main.Appearance.HeaderPanel.Font = new Font("Arial"10, FontStyle.Bold);

            uiView_Main.Appearance.Row.Font = new Font("Arial"10, FontStyle.Bold);

 

            //ColumnHeader 가운데 정렬

            for (int idx = 0; idx < dt.Columns.Count; idx++)

            {

                uiView_Main.Columns[idx].AppearanceHeader.TextOptions.HAlignment = 

                                                DevExpress.Utils.HorzAlignment.Center;

            }

        }

 

        public DataTable GetData()

        {

            DataTable dt = new DataTable();

            dt.Columns.Add("Name");

            dt.Columns.Add("Age");

            dt.Columns.Add("Grade");

            dt.Columns.Add("Score");

            dt.Columns.Add("Check");

 

            dt.Rows.Add(new string[] { "범범조조""28""2""100""True" });

            dt.Rows.Add(new string[] { "황선홍""56""3""10""True" });

            dt.Rows.Add(new string[] { "안정환""34""2""78""False" });

            dt.Rows.Add(new string[] { "설기현""33""1""54""False" });

            dt.Rows.Add(new string[] { "아이유""28""1""45""True" });

            dt.Rows.Add(new string[] { "박지성""23""4""10""False" });

 

            return dt;

        }

    }

}

 

Colored by Color Scripter

cs


폰트 변경, 컬럼헤더 정렬 전



폰트 변경, 컬럼헤더 정렬 후




위와 같이 ColumnHeader 가 가운데 정렬이 되었고, 폰트와 크기 또한 제가 소스 코드에서 지정한 대로 변경된 것을 확인하실 수 있습니다.

 

이로써, 오늘은 GridControl에서 Column, Row 폰트 변경 및 ColumnHeader 가운데 정렬 하는 방법에 대해서 알아 보았습니다.

 

감사합니다.


728x90

이 글을 공유하기

댓글

Designed by JB FACTORY