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

▶ UltraGrid 클래스 : IEditorDataFilter 인터페이스 사용하기 예제

using System.Data;
using System.Globalization;

using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;

private UltraGrid ultraGrid;

...

DataTable dataTable = new DataTable("WorkSchedule");

dataTable.Columns.Add("Employee", typeof(string  ));
dataTable.Columns.Add("DayOff"  , typeof(DateTime));

dataTable.Rows.Add("Alice", null);
dataTable.Rows.Add("Bob"  , null);
dataTable.Rows.Add("Cher" , null);
dataTable.Rows.Add("Don"  , null);
dataTable.Rows.Add("Ellen", null);


this.ultraGrid.Text       = "Employee Schedule";
this.ultraGrid.DataSource = dataTable;


EditorWithCombo editorWithCombo = new EditorWithCombo();

editorWithCombo.DataFilter = new DateTimeEditorDataFilter();


ValueList valueList = new ValueList();

string[] dayNameArray = CultureInfo.CurrentCulture.DateTimeFormat.DayNames;

for(int i = 0; i < dayNameArray.Length; i++)
{
    valueList.ValueListItems.Add((DayOfWeek)i, dayNameArray[i]);
}


UltraGridColumn column = this.ultraGrid.DisplayLayout.Bands[0].Columns["DayOff"];

column.Editor    = editorWithCombo;
column.ValueList = valueList;

 

728x90

 

▶ UltraGrid 클래스 : IEditorDataFilter 인터페이스 사용하기

using System;
using System.Globalization;

using Infragistics.Win;

/// <summary>
/// DateTime 에디터 데이터 필터
/// </summary>
public class DateTimeEditorDataFilter : IEditorDataFilter
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Method
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    // IEditorDataFilter
    #region 변환하기 - Convert(editorDataFilterConvertArgs)

    /// <summary>
    /// 변환하기
    /// </summary>
    /// <param name="editorDataFilterConvertArgs">EditorDataFilterConvertArgs</param>
    /// <returns>변환 값</returns>
    public object Convert(EditorDataFilterConvertArgs editorDataFilterConvertArgs)
    {
        switch(editorDataFilterConvertArgs.Direction)
        {
            case ConversionDirection.DisplayToEditor :
            {
                string value = editorDataFilterConvertArgs.Value as string;

                if(value != null)
                {
                    if(value.ToLower().Equals("today"))
                    {
                        editorDataFilterConvertArgs.Handled = true;
                        editorDataFilterConvertArgs.IsValid = true;

                        return DateTime.Today;
                    }
                }

                break;
            }

            case ConversionDirection.EditorToDisplay :
            {
                if(editorDataFilterConvertArgs.Value is DayOfWeek)
                {
                    DayOfWeek dayOfWeek = (DayOfWeek)editorDataFilterConvertArgs.Value;
                    DateTime  dateTime  = this.GetDateTime(dayOfWeek);

                    if(dateTime == DateTime.Today)
                    {
                        string[] dayNameArray = CultureInfo.CurrentCulture.DateTimeFormat.DayNames;

                        editorDataFilterConvertArgs.Handled = true;
                        editorDataFilterConvertArgs.IsValid = true;

                        return dayNameArray[(int)dayOfWeek] + " (Today)";
                    }
                }

                break;
            }

            case ConversionDirection.EditorToOwner :
            {
                if(editorDataFilterConvertArgs.Value is DayOfWeek)
                {
                    DayOfWeek dayOfWeek = (DayOfWeek)editorDataFilterConvertArgs.Value;
                    DateTime  dateTime  = this.GetDateTime(dayOfWeek);

                    editorDataFilterConvertArgs.Handled = true;
                    editorDataFilterConvertArgs.IsValid = true;

                    return dateTime;
                }

                break;
            }

            case ConversionDirection.OwnerToEditor :
            {
                if(editorDataFilterConvertArgs.Value is DateTime)
                {
                    DateTime dateTime = (DateTime)editorDataFilterConvertArgs.Value;

                    editorDataFilterConvertArgs.Handled = true;
                    editorDataFilterConvertArgs.IsValid = true;

                    return dateTime.DayOfWeek;
                }

                break;
            }
        }

        return editorDataFilterConvertArgs.Value;
    }

    #endregion

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

    #region 일시 구하기 - GetDateTime(dayOfWeek)

    /// <summary>
    /// 일시 구하기
    /// </summary>
    /// <param name="dayOfWeek">DayOfWeek</param>
    /// <returns>일시</returns>
    private DateTime GetDateTime(DayOfWeek dayOfWeek)
    {
        for(int i = 0; i < 7; i ++)
        {
            DateTime dateTime = DateTime.Today.AddDays((double)i);

            if(dateTime.DayOfWeek == dayOfWeek)
            {
                return dateTime;
            }
        }

        return DateTime.Today;
    }

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

댓글을 달아 주세요