■ TableView 엘리먼트의 행/셀 컨텍스트 메뉴에서 행을 삭제하는 방법을 보여준다.
▶ 예제 코드 (XAML)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<dxg:GridControl x:Name="gridControl"> <dxg:GridControl.Columns> <dxg:GridColumn FieldName="UserName" Header="User Name" /> <dxg:GridColumn FieldName="RegistrationDate" Header="Registration Date" /> </dxg:GridControl.Columns> <dxg:GridControl.View> <dxg:TableView x:Name="tableView"> <dxg:TableView.RowCellMenuCustomizations> <dxb:BarButtonItem x:Name="deleteRowBarButtonItem" Content="Delete Row" ItemClick="deleteRowBarButtonItem_ItemClick" /> <dxb:BarButtonItem x:Name="copyCellDataBarButtonItem" Content="Copy Cell Data" ItemClick="copyCellDataBarButtonItem_ItemClick" /> </dxg:TableView.RowCellMenuCustomizations> </dxg:TableView> </dxg:GridControl.View> </dxg:GridControl> |
▶ 예제 코드 (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 |
using DevExpress.Xpf.Bars; using DevExpress.Xpf.Grid; #region Delete Row 바 버튼 항목 항목 클릭시 처리하기 - deleteRowBarButtonItem_ItemClick(sender, e) /// <summary> /// Delete Row 바 버튼 항목 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void deleteRowBarButtonItem_ItemClick(object sender, ItemClickEventArgs e) { GridCellMenuInfo gridCellMenuInfo = this.tableView.GridMenu.MenuInfo as GridCellMenuInfo; if(gridCellMenuInfo != null && gridCellMenuInfo.Row != null) { int rowHandle = gridCellMenuInfo.Row.RowHandle.Value; this.tableView.DeleteRow(rowHandle); } } #endregion #region Copy Cell Data 바 버튼 항목 항목 클릭시 처리하기 - copyCellDataBarButtonItem_ItemClick(sender, e) /// <summary> /// Copy Cell Data 바 버튼 항목 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void copyCellDataBarButtonItem_ItemClick(object sender, ItemClickEventArgs e) { GridCellMenuInfo gridCellMenuInfo = this.tableView.GridMenu.MenuInfo as GridCellMenuInfo; if(gridCellMenuInfo != null && gridCellMenuInfo.Row != null) { int rowHandle = gridCellMenuInfo.Row.RowHandle.Value; GridColumn gridColumn = gridCellMenuInfo.Column as GridColumn; object cellValue = this.gridControl.GetCellValue(rowHandle, gridColumn); Clipboard.SetText(cellValue == null ? string.Empty : cellValue.ToString()); } } #endregion |