用户管理表格右键弹出菜单:修改密码,复制权限,锁定用户|C/S框架网
用户管理表格右键弹出菜单:修改密码,复制权限,锁定用户|C/S框架网
AddMenuItem扩展方法:
参考文档:
《用户管理》功能作为C/S系统快速开发框架提供的核心关键功能,在《用户管理》表格中点击鼠标右键可弹出菜单,支持修改密码、复制权限、解除用户权限、锁定用户、解除锁定等功能。
DevExpress表格组件是GridControl,内置预设视图组件GridView,我们看到的单元格内容实际是GridView展示的数据,在GridView组件的列头(Column)以及单元格(Cell)区域点击鼠标右键弹出不同功能的类型的菜单。
下图是在单元格点击鼠标右键弹出的菜单项:
下图是在表格列头点击鼠标右键弹出的菜单项:
在表格列头区域弹出菜单包含DevExpress内置菜单功能以及用户自定义扩展菜单项。
代码实现:
C# Code:
//注册表格弹出菜单扩展功能
frmGridCustomize.RegisterGrid(gvSummary);
//添加自定义菜单项
frmGridCustomize.AddMenuItem(gvSummary, "修改密码", Globals.LoadImage("16_08.png"), OnChangePwdClick, true);
//管理员才添加弹出菜单
if (Loginer.CurrentUser.IsAdmin())
{
frmGridCustomize.AddMenuItem(gvSummary, "复制权限", Globals.LoadImage("16_01.png"), OnCopyRights, true);
frmGridCustomize.AddMenuItem(gvSummary, "解除用户的权限", Globals.LoadImage("16_04.png"), OnCancelRights, false);
frmGridCustomize.AddMenuItem(gvSummary, "锁定当前用户", Globals.LoadImage("16_05.png"), OnLockUser, true);
frmGridCustomize.AddMenuItem(gvSummary, "解除锁定", Globals.LoadImage("16_06.png"), OnUnLockUser, false);
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
//注册表格弹出菜单扩展功能
frmGridCustomize.RegisterGrid(gvSummary);
//添加自定义菜单项
frmGridCustomize.AddMenuItem(gvSummary, "修改密码", Globals.LoadImage("16_08.png"), OnChangePwdClick, true);
//管理员才添加弹出菜单
if (Loginer.CurrentUser.IsAdmin())
{
frmGridCustomize.AddMenuItem(gvSummary, "复制权限", Globals.LoadImage("16_01.png"), OnCopyRights, true);
frmGridCustomize.AddMenuItem(gvSummary, "解除用户的权限", Globals.LoadImage("16_04.png"), OnCancelRights, false);
frmGridCustomize.AddMenuItem(gvSummary, "锁定当前用户", Globals.LoadImage("16_05.png"), OnLockUser, true);
frmGridCustomize.AddMenuItem(gvSummary, "解除锁定", Globals.LoadImage("16_06.png"), OnUnLockUser, false);
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
C# Code:
/// <summary>
/// AddMenuItem扩展方法,表格弹出菜单添加自定义菜单项
/// </summary>
/// <param name="view">GridView表格</param>
/// <param name="caption">菜单标题</param>
/// <param name="image">菜单图片</param>
/// <param name="clickEvent">click事件</param>
/// <param name="beginGroup">是否带分割线的菜单项</param>
public static void AddMenuItem(GridView view, string caption, Image image, EventHandler clickEvent, bool beginGroup)
{
List<DXMenuItem> list = (List<DXMenuItem>)_ExtraMenuClick[view];
if (list == null)
{
list = new List<DXMenuItem>();
_ExtraMenuClick.Add(view, list);
}
DXMenuItem item = new DXMenuItem(caption);
item.Image = image;
item.Click += new EventHandler(clickEvent);
item.Tag = view;//保存GridView引用,在DXMenuItem事件内快速找到GridView
item.BeginGroup = beginGroup;
list.Add(item);
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
/// <summary>
/// AddMenuItem扩展方法,表格弹出菜单添加自定义菜单项
/// </summary>
/// <param name="view">GridView表格</param>
/// <param name="caption">菜单标题</param>
/// <param name="image">菜单图片</param>
/// <param name="clickEvent">click事件</param>
/// <param name="beginGroup">是否带分割线的菜单项</param>
public static void AddMenuItem(GridView view, string caption, Image image, EventHandler clickEvent, bool beginGroup)
{
List<DXMenuItem> list = (List<DXMenuItem>)_ExtraMenuClick[view];
if (list == null)
{
list = new List<DXMenuItem>();
_ExtraMenuClick.Add(view, list);
}
DXMenuItem item = new DXMenuItem(caption);
item.Image = image;
item.Click += new EventHandler(clickEvent);
item.Tag = view;//保存GridView引用,在DXMenuItem事件内快速找到GridView
item.BeginGroup = beginGroup;
list.Add(item);
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
参考文档:
DevExpress表格样式配置窗体frmGridCustomize最新版下载:
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网