■ UltraGrid 클래스에서 IEditorDataFilter 인터페이스를 사용하는 방법을 보여준다.
▶ UltraGrid 클래스 : IEditorDataFilter 인터페이스 사용하기 예제 (C#)
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 |
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; |
▶ UltraGrid 클래스 : IEditorDataFilter 인터페이스 사용하기 (C#)
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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
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 } |