[DEVEXPRESS/WINFORM] TreeList 클래스 : PopupMenuShowing 이벤트를 사용해 컨텍스트 메뉴에서 특정 메뉴 제거하기
DevExpress/WinForm 2020. 5. 30. 09:36728x90
반응형
728x170
▶ MainForm.cs
using System;
using System.Linq;
using DevExpress.Utils;
using DevExpress.Utils.Menu;
using DevExpress.XtraEditors;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Localization;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : XtraForm
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
Load += Form_Load;
this.treeList.PopupMenuShowing += treeList_PopupMenuShowing;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 폼 로드시 처리하기 - Form_Load(sender, e)
/// <summary>
/// 폼 로드시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_Load(object sender, EventArgs e)
{
this.treeList.RowHeight = 25;
this.treeList.OptionsView.AutoWidth = false;
this.treeList.OptionsBehavior.ReadOnly = true;
this.treeList.OptionsBehavior.PopulateServiceColumns = true;
this.treeList.KeyFieldName = "ID";
this.treeList.ParentFieldName = "RegionID";
this.treeList.DataSource = SalesData.GetSalesDataList();
this.treeList.Columns[this.treeList.KeyFieldName ].Visible = false;
this.treeList.Columns[this.treeList.ParentFieldName].Visible = false;
this.treeList.BestFitColumns();
this.treeList.ExpandAll();
}
#endregion
#region 트리 리스트 팝업 메뉴 표시시 처리하기 - treeList_PopupMenuShowing(sender, e)
/// <summary>
/// 트리 리스트 팝업 메뉴 표시시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void treeList_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
{
TreeList treeList = sender as TreeList;
TreeListHitInfo hitInfo = treeList.CalcHitInfo(e.Point);
if(hitInfo.HitInfoType == HitInfoType.Column)
{
TreeListStringId id = GetColumnChooserMenuItemID(treeList);
string caption = TreeListLocalizer.Active.GetLocalizedString(id);
DXMenuItem menuItem = e.Menu.Items.FirstOrDefault(x => x.Caption == caption);
e.Menu.Items.Remove(menuItem);
}
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region Column Chooser 메뉴 항목 ID 구하기 - GetColumnChooserMenuItemID(treeList)
/// <summary>
/// Column Chooser 메뉴 항목 ID 구하기
/// </summary>
/// <param name="treeList">트리 리스트</param>
/// <returns>Column Chooser 메뉴 항목 ID</returns>
private TreeListStringId GetColumnChooserMenuItemID(TreeList treeList)
{
if
(
treeList.OptionsView.ShowBandsMode == DefaultBoolean.True ||
(treeList.OptionsView.ShowBandsMode == DefaultBoolean.Default && treeList.Bands.Count > 0)
)
{
return TreeListStringId.MenuColumnBandCustomization;
}
return TreeListStringId.MenuColumnColumnCustomization;
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
댓글을 달아 주세요