■ UltraGrid 클래스의 ClickCell 이벤트를 사용해 컨텍스트 메뉴를 보여주는 방법을 보여준다.
▶ 예제 코드 (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 130 131 132 133 134 135 136 |
using Infragistics.Win.UltraWinGrid; using Infragistics.Win.UltraWinToolbars; private UltraGrid ultraGrid; private MouseButtons mouseButtons = MouseButtons.None; private UltraToolbarsManager ultraToolbarsManager; ... #region 폼 로드시 처리하기 - Form_Load(sender, e) /// <summary> /// 폼 로드시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void Form_Load(object sender, EventArgs e) { PopupMenuTool operationPopupMenuTool = new Infragistics.Win.UltraWinToolbars.PopupMenuTool("Operation"); ButtonTool deleteButtonTool = new Infragistics.Win.UltraWinToolbars.ButtonTool("Delete"); deleteButtonTool.SharedProps.Caption = "Delete"; this.ultraToolbarsManager.Tools.AddRange(new ToolBase[] { operationPopupMenuTool, deleteButtonTool }); operationPopupMenuTool.Tools.AddTool("Delete"); this.ultraGrid1.MouseDown += ultraGrid_MouseDown; this.ultraGrid1.ClickCell += ultraGrid_ClickCell; this.ultraToolbarsManager.ToolClick += ultraToolbarsManager_ToolClick; this.ultraGrid1.DataSource = GetDataTable(); } #endregion #region UltraGrid 마우스 DOWN 처리하기 - ultraGrid_MouseDown(sender, e) /// <summary> /// UltraGrid 마우스 DOWN 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void ultraGrid_MouseDown(object sender, MouseEventArgs e) { this.mouseButtons = e.Button; } #endregion #region UltraGrid 셀 클릭시 처리하기 - ultraGrid_ClickCell(sender, e) /// <summary> /// UltraGrid 셀 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void ultraGrid_ClickCell(object sender, ClickCellEventArgs e) { this.ultraGrid1.Selected.Rows.Clear(); e.Cell.Row.Activate(); e.Cell.Row.Selected = true; this.Text = string.Format("{0}: {1}", e.Cell.Column.Header.Caption, e.Cell.Value.ToString()); if(this.mouseButtons == MouseButtons.Right) { this.ultraToolbarsManager.ShowPopup("Operation"); } } #endregion #region UltraToolbarsManager 도구 클릭시 처리하기 - ultraToolbarsManager_ToolClick(sender, e) /// <summary> /// UltraToolbarsManager 도구 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void ultraToolbarsManager_ToolClick(object sender, ToolClickEventArgs e) { switch(e.Tool.Key) { case "Delete" : if(this.ultraGrid1.ActiveRow != null) { this.ultraGrid1.ActiveRow.Delete(); } break; } } #endregion #region 데이터 테이블 구하기 - GetDataTable() /// <summary> /// 데이터 테이블 구하기 /// </summary> /// <returns>데이터 테이블</returns> private DataTable GetDataTable() { DataTable table = new DataTable(); table.Columns.Add("Sequence", typeof(int )); table.Columns.Add("Name" , typeof(string)); table.Columns.Add("Sex" , typeof(string)); table.Columns.Add("Grade" , typeof(string)); table.Columns.Add("Korean" , typeof(double)); table.Columns.Add("English" , typeof(double)); table.Columns.Add("Math" , typeof(double)); table.Columns.Add("Science" , typeof(double)); table.Rows.Add(1, "홍길동", "남자", "1", 100, 95, 100, 85 ); table.Rows.Add(2, "김철수", "남자", "2", 100, 85, 90 , 95 ); table.Rows.Add(3, "김영희", "여자", "3", 90 , 90, 95 , 100); table.AcceptChanges(); return table; } #endregion |