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);
		};
	}
}	

效果:

YESWEB框架表格自定义右键菜单

版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
张国生
评论列表

发表评论

评论内容
昵称:
关联文章

YESWEB框架表格定义菜单
DevExpress RibbonControl 定义弹出菜单
Devexpress GridControl GridView添加菜单
定义表格操作按钮 GridControlEmbeddedNavigator
窗体GridView布局定义
Devexpress XtraTabbedMdiManager添加关闭菜单 (关闭当前页、关闭其它页、所有关闭)
win11菜单恢复默认显示更多选项
YES-Win Winform开发框架 定义查询方法并在表格中展示
窗体定义权限操作按钮
.NET Core 定义中间件 Middleware
YESWEB开发框架 技术要求
AS.NET Core定义类中全局访问HttpContext
自己创造一个格式,定义文件后缀名
GZUpdate自动升级之定义更新补丁程序
YESWEB 开发框架 路由配置文件 作用原理
C# 配置文件增加定义节点
Excel定义格式千分符
C# Winform 定义异常处理方法
TinyMCE定义字体大小列表
SQL Prompt定义代码片段