WPF에서 DevExpress그리드 컨트롤을 생성하고 컬럼과 데이터를 추가해보겠습니다.


DevExpress란 간단하게 설명하자면 .NET 기반 컴포넌트 라이브러리중 하나입니다. 국내에서는 무겁기로 소문나있지만 사용하는 곳이 꽤 많습니다. 해외에서는 굉장히 많이 사용중이라고 합니다. 개인이 구입하기에는 가격이 많이 부담스러우실 수 있습니다. 여러가지 화려한 시각적인 효과와 다양한 툴을 제공합니다.




[1]. 먼저 프로젝트를 생성한 후 그리드 컨트롤을 하나 만들겠습니다.

   <dxg:GridControl AutoGenerateColumns="AddNew" EnableSmartColumnsGeneration="True" >

            <dxg:GridControl.View>

                <dxg:TableView AllowPerPixelScrolling="True" ShowTotalSummary="True"/>

            </dxg:GridControl.View>

        </dxg:GridControl>



[2]. Model 코드와 ViewModel코드를 작성합니다.

//Model 코드 작성

    public class Customer

    {

        public string Name { get; set; }

        public string Country { get; set; }

        public int Visits { get; set; }

        public DateTime? Birthday { get; set; }


        public static List<Customer> GetCustomers()

        {

            List<Customer> people = new List<Customer>();

            people.Add(new Customer() { Name = "홍길동", Country = "KOREA", Visits = 4, Birthday = new DateTime(1980, 1, 1) });

            people.Add(new Customer() { Name = "임꺽정", Country = "KOREA", Visits = 2, Birthday = new DateTime(1966, 4, 15) });

            people.Add(new Customer() { Name = "제이나", Country = "ALLIANCE", Visits = 6, Birthday = new DateTime(1982, 3, 11) });

            people.Add(new Customer() { Name = "헬스크림", Country = "HORDE", Visits = 11, Birthday = new DateTime(1977, 12, 5) });

            people.Add(new Customer() { Name = "란두인", Country = "ALLIANCE", Visits = 8, Birthday = new DateTime(1956, 9, 5) });

            people.Add(new Customer() { Name = "럭스", Country = "DEMACIA", Visits = 5, Birthday = new DateTime(1990, 2, 27) });

            people.Add(new Customer() { Name = "신드라", Country = "Ionia", Visits = 21, Birthday = new DateTime(1965, 5, 5) });

            people.Add(new Customer() { Name = "다리우스", Country = "Noxus", Visits = 8, Birthday = new DateTime(1987, 11, 9) });

            people.Add(new Customer() { Name = "소라카", Country = "Ionia", Visits = 1, Birthday = new DateTime(1949, 6, 18) });

            people.Add(new Customer() { Name = "자르반4세", Country = "DEMACIA", Visits = 3, Birthday = new DateTime(1989, 1, 8) });

            people.Add(new Customer() { Name = "아리", Country = "Ionia", Visits = 4, Birthday = new DateTime(1972, 9, 14) });

            people.Add(new Customer() { Name = "뽀삐", Country = "DEMACIA", Visits = 6, Birthday = new DateTime(1989, 5, 7) });

            people.Add(new Customer() { Name = "드레이븐", Country = "Noxus", Visits = 19, Birthday = new DateTime(1971, 10, 3) });

            return people;

        }

    }


    //ViewModel 코드 작성

    public class MainWindowViewModel

    {

        public MainWindowViewModel()

        {

            this.Customers = Customer.GetCustomers();

        }

        public List<Customer> Customers { get; set; }

    }



[3]. DataContext를 연결해줍니다.




[4].그리드컨트롤에 ItemSource로 가서 아까 연결했던 DataContext를 연결해줍니다.




[5]. 마지막으로 정상적으로 출력되는지 결과를 확인합니다.


성공입니다~!   수고하셨습니다!






+ Recent posts