YESWEB框架表格自定义右键菜单
注册表格右键菜单,并添加菜单显示事件,在菜单弹出事件中添加自定义的菜单选项
C# 全选
var gvPopupMenu = GridViewCommonPopupMenu.Register(gvDetail_Order_Basket);
gvPopupMenu.PopupMenuShowing += FrmPrOrder_PopupMenuShowing;
GridView表格右键弹出菜单事件
C# 全选
private void Gv_PopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e)
{
GridView view = sender as GridView;
if (GridMenuType.Row == e.MenuType)
{
var fieldName = view.CalcHitInfo(e.Point).Column.FieldName;
// 当前选中的行
var currentRow = view.GetFocusedRow() as YESWEB.CommonModels.ReportCenter.ReportModel;
DXMenuItem itemCopy = new DXMenuItem("复制模板");
itemCopy.Image = DevExpress.Images.ImageResourceCache.Default.GetImageById("edit", DevExpress.Utils.Design.ImageSize.Size16x16, DevExpress.Utils.Design.ImageType.Office2013);
itemCopy.BeginGroup = true;
itemCopy.Click += (s_sender, s_e) =>
{
Msg.ShowInformation("点击了修改");
};
}
}
PopupMenuShowing事件中获得点击的行和列
C# 全选
private void _gridView_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
{
GridView view = sender as GridView;
if (GridMenuType.Row == e.MenuType)
{
GridColumn column = view.CalcHitInfo(e.Point).Column;
string colName = column.Caption;
string cellTxt = view.GetFocusedRowCellValue(column) + "";
var item_CopyCellValue = CreatePopupMenuItem(e.Menu.Items, $"复制[{colName}]", LoadUIImage.LoadImage("copy_16x16.png"), true);
item_CopyCellValue.Click += (s_sender, s_e) =>
{
Clipboard.SetText(cellTxt);
};
}
}
效果:
版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
YESWinform 张国生