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

TestProject.zip
0.01MB

▶ SampleData.cs

using System.Data;

namespace TestProject
{
    /// <summary>
    /// 샘플 데이터
    /// </summary>
    public class SampleData
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Public

        #region 샘플 테이블 구하기 - GetSampleTable(count)

        /// <summary>
        /// 샘플 테이블 구하기
        /// </summary>
        /// <param name="count">카운트</param>
        /// <returns>샘플 테이블</returns>
        public static DataTable GetSampleTable(int count)
        {
            DataTable table = new DataTable();

            table.Columns.Add("항목1", typeof(string));
            table.Columns.Add("항목2", typeof(string));
            table.Columns.Add("항목3", typeof(string));
            table.Columns.Add("항목4", typeof(string));
            table.Columns.Add("항목5", typeof(string));

            for(int i = 0; i < count; i++)
            {
                table.Rows.Add("값 " + i.ToString(), "값 " + i.ToString(), "값 " + i.ToString(), "값 " + i.ToString(), "값 " + i.ToString());
            }

            table.AcceptChanges();

            return table;
        }

        #endregion
    }
}

 

728x90

 

▶ DataTableVirtualSourcePropertyDescriptor.cs

using System;
using System.ComponentModel;

namespace TestProject
{
    /// <summary>
    /// 데이터 테이블 가상 소스 속성 설명자
    /// </summary>
    public class DataTableVirtualSourcePropertyDescriptor : PropertyDescriptor
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 속성명
        /// </summary>
        private string propertyName;

        /// <summary>
        /// 속성 타입
        /// </summary>
        private Type propertyType;

        /// <summary>
        /// 읽기 전용 여부
        /// </summary>
        private bool isReadOnly;

        /// <summary>
        /// 가상 소스
        /// </summary>
        private DataTableVirtualSource virtualSource;

        /// <summary>
        /// 인덱스
        /// </summary>
        private int index;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 컴포넌트 타입 - ComponentType

        /// <summary>
        /// 컴포넌트 타입
        /// </summary>
        public override Type ComponentType
        {
            get
            {
                return typeof(DataTableVirtualSource);
            }
        }

        #endregion
        #region 명칭 - Name

        /// <summary>
        /// 명칭
        /// </summary>
        public override string Name
        {
            get
            {
                return this.propertyName;
            }
        }

        #endregion
        #region 속성 타입 - PropertyType

        /// <summary>
        /// 속성 타입
        /// </summary>
        public override Type PropertyType
        {
            get
            {
                return this.propertyType;
            }
        }

        #endregion
        #region 읽기 전용 여부 - IsReadOnly

        /// <summary>
        /// 읽기 전용 여부
        /// </summary>
        public override bool IsReadOnly
        {
            get
            {
                return this.isReadOnly;
            }
        }

        #endregion

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

        #region 생성자 - DataTableVirtualSourcePropertyDescriptor(virtuslSource, index, propertyName, propertyType, isReadOnly)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="virtuslSource">가상 소스</param>
        /// <param name="index">인덱스</param>
        /// <param name="propertyName">속성명</param>
        /// <param name="propertyType">속성 타입</param>
        /// <param name="isReadOnly">읽기 전용 여부</param>
        public DataTableVirtualSourcePropertyDescriptor(DataTableVirtualSource virtuslSource, int index, string propertyName, Type propertyType, bool isReadOnly) : base(propertyName, null)
        {
            this.virtualSource = virtuslSource;
            this.index         = index;
            this.propertyName  = propertyName;
            this.propertyType  = propertyType;
            this.isReadOnly    = isReadOnly;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 값 리셋 가능 여부 구하기 - CanResetValue(component)

        /// <summary>
        /// 값 리셋 가능 여부 구하기
        /// </summary>
        /// <param name="component">컴포넌트</param>
        /// <returns>값 리셋 가능 여부</returns>
        public override bool CanResetValue(object component)
        {
            return false;
        }

        #endregion
        #region 값 리셋하기 - ResetValue(component)

        /// <summary>
        /// 값 리셋하기
        /// </summary>
        /// <param name="component">컴포넌트</param>
        public override void ResetValue(object component)
        {
        }

        #endregion
        #region 값 설정하기 - SetValue(component, value)

        /// <summary>
        /// 값 설정하기
        /// </summary>
        /// <param name="component">컴포넌트</param>
        /// <param name="value">값</param>
        public override void SetValue(object component, object value)
        {
            this.virtualSource.SetRowValue(component, this.index, value);
        }

        #endregion
        #region 값 구하기 - GetValue(component)

        /// <summary>
        /// 값 구하기
        /// </summary>
        /// <param name="component">컴포넌트</param>
        /// <returns>값</returns>
        public override object GetValue(object component)
        {
            return this.virtualSource.GetRowValue(component, this.index);
        }

        #endregion
        #region 값 직렬화 필수 여부 구하기 - ShouldSerializeValue(component)

        /// <summary>
        /// 값 직렬화 필수 여부 구하기
        /// </summary>
        /// <param name="component">컴포넌트</param>
        /// <returns>값 직렬화 필수 여부</returns>
        public override bool ShouldSerializeValue(object component)
        {
            return true;
        }

        #endregion
    }
}

 

300x250

 

▶ DataTableVirtualSource.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;

namespace TestProject
{
    /// <summary>
    /// 데이터 테이블 가상 소스
    /// </summary>
    public class DataTableVirtualSource : IList, ITypedList
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 소스 테이블
        /// </summary>
        private DataTable sourceTable;

        /// <summary>
        /// 로우 카운트
        /// </summary>
        private int rowCount;

        /// <summary>
        /// 컬럼 카운트
        /// </summary>
        private int columnCount;

        /// <summary>
        /// 속성 설명자 컬렉션
        /// </summary>
        private PropertyDescriptorCollection propertyDescriptorCollection;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 데이터 테이블 - DataTable

        /// <summary>
        /// 데이터 테이블
        /// </summary>
        public DataTable DataTable
        {
            get
            {
                return this.sourceTable;
            }
        }

        #endregion
        #region 로우 카운트 - RowCount

        /// <summary>
        /// 로우 카운트
        /// </summary>
        public int RowCount
        { 
            get
            {
                return this.rowCount;
            }
            set
            {
                if(value < 1)
                {
                    value = 0;
                }

                if(this.rowCount == value)
                {
                    return;
                }

                this.rowCount = value;
            }
        }

        #endregion
        #region 컬럼 카운트 - ColumnCount

        /// <summary>
        /// 컬럼 카운트
        /// </summary>
        public int ColumnCount
        { 
            get
            {
                return this.columnCount;
            }
            set
            {
                if(value < 1)
                {
                    value = 0;
                }

                if(this.columnCount == value)
                {
                    return;
                }

                this.columnCount = value;

                SetPropertyDescriptorCollection();
            }
        }

        #endregion
        #region (IList) 카운트 - Count

        /// <summary>
        /// 카운트
        /// </summary>
        public virtual int Count
        {
            get
            {
                return this.rowCount;
            }
        }

        #endregion
        #region (IList) 동기화 여부 - IsSynchronized

        /// <summary>
        /// 동기화 여부
        /// </summary>
        public virtual bool IsSynchronized
        {
            get
            {
                return true;
            }
        }

        #endregion
        #region (IList) 동기 루트 - SyncRoot

        /// <summary>
        /// 동기 루트
        /// </summary>
        public virtual object SyncRoot
        {
            get
            {
                return true;
            }
        }

        #endregion
        #region (IList) 읽기 전용 여부 - IsReadOnly

        /// <summary>
        /// 읽기 전용 여부
        /// </summary>
        public virtual bool IsReadOnly
        {
            get
            {
                return false;
            } 
        }

        #endregion
        #region (IList) 고정 크기 여부 - IsFixedSize

        /// <summary>
        /// 고정 크기 여부
        /// </summary>
        public virtual bool IsFixedSize
        {
            get
            {
                return true;
            } 
        }

        #endregion
        #region (IList) 인덱서 - this[index]

        /// <summary>
        /// 인덱서
        /// </summary>
        /// <param name="index">인덱스</param>
        /// <returns>값</returns>
        public object this[int index]
        { 
            get
            {
                return this.sourceTable.Rows[index];
            }
            set
            {
            }
        }

        #endregion

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

        #region 생성자 - VirtualTable(sourceTable)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="sourceTable">소스 테이블</param>
        public DataTableVirtualSource(DataTable sourceTable)
        {
            this.sourceTable = sourceTable;
            this.rowCount    = GetRowCount();
            this.columnCount = GetColumnCount();

            SetPropertyDescriptorCollection();
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Internal

        #region 행 값 설정하기 - SetRowValue(row, columnIndex, value)

        /// <summary>
        /// 행 값 설정하기
        /// </summary>
        /// <param name="row">행 객체</param>
        /// <param name="columnIndex">컬럼 인덱스</param>
        /// <param name="value">값</param>
        internal void SetRowValue(object row, int columnIndex, object value)
        {
            DataRow dataRow = row as DataRow;

            if(dataRow != null)
            {
                dataRow[columnIndex] = value;
            }
        }

        #endregion
        #region 행 값 구하기 - GetRowValue(row, columnIndex)

        /// <summary>
        /// 행 값 구하기
        /// </summary>
        /// <param name="row">행 객체</param>
        /// <param name="columnIndex">컬럼 인덱스</param>
        /// <returns>행 값</returns>
        internal object GetRowValue(object row, int columnIndex)
        {
            DataRow dataRow = row as DataRow;

            if(dataRow != null)
            {
                return dataRow[columnIndex];
            }
            else
            {
                return null;
            }
        }

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region (IList) 열거자 구하기 - GetEnumerator()
        
        /// <summary>
        /// 열거자 구하기
        /// </summary>
        /// <returns>열거자</returns>
        public virtual IEnumerator GetEnumerator()
        { 
            return null;
        }

        #endregion
        #region (IList) 복사하기 - CopyTo(array, index)

        /// <summary>
        /// 복사하기
        /// </summary>
        /// <param name="array">배열</param>
        /// <param name="index">인덱스</param>
        public virtual void CopyTo(Array array, int index)
        {
        }

        #endregion
        #region (IList) 추가하기 - Add(value)

        /// <summary>
        /// 추가하기
        /// </summary>
        /// <param name="value">값</param>
        /// <returns>처리 결과</returns>
        public virtual int Add(object value)
        {
            throw new NotImplementedException();
        }

        #endregion
        #region (IList) 지우기 - Clear()

        /// <summary>
        /// 지우기
        /// </summary>
        public virtual void Clear()
        {
            throw new NotImplementedException();
        }

        #endregion
        #region (IList) 포함 여부 구하기 - Contains(value)

        /// <summary>
        /// 포함 여부 구하기
        /// </summary>
        /// <param name="value">값</param>
        /// <returns>포함 여부</returns>
        public virtual bool Contains(object value)
        {
            throw new NotImplementedException();
        }

        #endregion
        #region (IList) 인덱스 구하기 - IndexOf(value)

        /// <summary>
        /// 인덱스 구하기
        /// </summary>
        /// <param name="value">값</param>
        /// <returns>인덱스</returns>
        public virtual int IndexOf(object value)
        {
            throw new NotImplementedException();
        }

        #endregion
        #region (IList) 삽입하기 - Insert(index, value)

        /// <summary>
        /// 삽입하기
        /// </summary>
        /// <param name="index">인덱스</param>
        /// <param name="value">값</param>
        public virtual void Insert(int index, object value)
        {
            throw new NotImplementedException();
        }

        #endregion
        #region (IList) 제거하기 - Remove(value)

        /// <summary>
        /// 제거하기
        /// </summary>
        /// <param name="value">값</param>
        public virtual void Remove(object value)
        { 
            throw new NotImplementedException();
        }

        #endregion
        #region (IList) 제거하기 - RemoveAt(index)

        /// <summary>
        /// 제거하기
        /// </summary>
        /// <param name="index">인덱스</param>
        public virtual void RemoveAt(int index)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region (ITypedList) 항목 속성 컬렉션 구하기 - GetItemProperties(propertyDescriptorArray)

        /// <summary>
        /// 항목 속성 컬렉션 구하기
        /// </summary>
        /// <param name="propertyDescriptorArray">속성 설명자 배열</param>
        /// <returns>항목 속성 컬렉션</returns>
        public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] propertyDescriptorArray)
        {
            return this.propertyDescriptorCollection;
        }

        #endregion
        #region (ITypedList) 리스트명 구하기 - GetListName(propertyDescriptorArray)

        /// <summary>
        /// 리스트명 구하기
        /// </summary>
        /// <param name="propertyDescriptorArray">속성 설명자 배열</param>
        /// <returns>리스트명</returns>
        public string GetListName(PropertyDescriptor[] propertyDescriptorArray)
        {
            return this.sourceTable.TableName;
        }

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Protected

        #region 속성 설명자 컬렉션 설정하기 - SetPropertyDescriptorCollection()

        /// <summary>
        /// 속성 설명자 컬렉션 설정하기
        /// </summary>
        protected virtual void SetPropertyDescriptorCollection()
        {
            DataTableVirtualSourcePropertyDescriptor[] propertyDescriptorArray = new DataTableVirtualSourcePropertyDescriptor[this.columnCount];

            for(int i = 0; i < this.columnCount; i++)
            {
                propertyDescriptorArray[i] = new DataTableVirtualSourcePropertyDescriptor
                (
                    this,
                    i,
                    this.sourceTable.Columns[i].ColumnName,
                    this.sourceTable.Columns[i].DataType,
                    false
                );
            }

            this.propertyDescriptorCollection = new PropertyDescriptorCollection(propertyDescriptorArray);
        }

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 로우 카운트 구하기 - GetRowCount()

        /// <summary>
        /// 로우 카운트 구하기
        /// </summary>
        /// <returns>로우 카운트</returns>
        private int GetRowCount()
        {
            if(this.sourceTable == null)
            {
                return 0;
            }

            return this.sourceTable.Rows.Count;
        }

        #endregion
        #region 컬럼 카운트 구하기 - GetColumnCount()

        /// <summary>
        /// 컬럼 카운트 구하기
        /// </summary>
        /// <returns>컬럼 카운트</returns>
        private int GetColumnCount()
        {
            if(this.sourceTable == null)
            {
                return 0;
            }

            return this.sourceTable.Columns.Count;
        }

        #endregion
    }
}

 

반응형

 

▶ MainForm.cs

using DevExpress.XtraEditors;

namespace TestProject
{
    /// <summary>
    /// 메인 폼
    /// </summary>
    public partial class MainForm : XtraForm
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainForm()

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

            DataTableVirtualSource virtualSource = new DataTableVirtualSource(SampleData.GetSampleTable(1_000_000));

            this.gridControl.DataSource = virtualSource;
        }

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

댓글을 달아 주세요