첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170
using System;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Windows.Forms;

namespace TestProject
{
    /// <summary>
    /// 메인 폼
    /// </summary>
    public partial class MainForm : Form
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Declaration
        ////////////////////////////////////////////////////////////////////////////////////////// Class

        /// <summary>
        /// 직원
        /// </summary>
        public class Employee
        {
            //////////////////////////////////////////////////////////////////////////////////////////////////// Property
            ////////////////////////////////////////////////////////////////////////////////////////// Public

            #region ID - ID

            /// <summary>
            /// ID
            /// </summary>
            public string ID { get; set; }

            #endregion

            #region 성명 - Name

            /// <summary>
            /// 성명
            /// </summary>
            public string Name { get; set; }

            #endregion

            #region 설명 - Description

            /// <summary>
            /// 설명
            /// </summary>
            public string Description { get; set; }

            #endregion
        }

        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 체크 리스트 박스
        /// </summary>
        private CheckedListBox checkedListBox;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainForm()

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

            this.checkedListBox = new CheckedListBox();

            this.checkedListBox.Dock = DockStyle.Fill;

            Controls.Add(this.checkedListBox);

            ListBox listBox = this.checkedListBox as ListBox;

            if(listBox != null)
            {
                listBox.DataSource    = GetCollection(); // DataSource 속성부터 설정해야 한다.
                listBox.DisplayMember = "Name";
                listBox.ValueMember   = "ID";
            }
        }

        #endregion

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

        #region 컬렉션 구하기 - GetCollection()

        /// <summary>
        /// 컬렉션 구하기
        /// </summary>
        /// <returns>컬렉션</returns>
        private ObservableCollection<Employee> GetCollection()
        {
            ObservableCollection<Employee> collection = new ObservableCollection<Employee>();

            for(int i = 0; i < 100; i++)
            {
                collection.Add(new Employee() { ID = (i + 1).ToString(), Name = "직원 " + (i + 1).ToString(), Description = "설명 " + (i + 1).ToString() });
            }

            return collection;
        }

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

댓글을 달아 주세요