上接扩展GridView控件(9) - 给数据行增加右键菜单

简介:
2、新建一个ContextMenu实体类,有六个属性
using System; 
using System.Collections.Generic; 
using System.Text; 
 
using System.ComponentModel; 
using System.Web.UI; 
 
namespace YYControls.SmartGridView 

         /// <summary> 
         /// ContextMenu 的摘要说明。 
         /// </summary> 
        [ToolboxItem( false)] 
         public  class ContextMenu 
        { 
                 private  string _icon; 
                 /// <summary> 
                 /// 文字左边的图标的链接 
                 /// </summary> 
                 public  string Icon 
                { 
                        get {  return _icon; } 
                        set { _icon = value; } 
                } 
 
                 private  string _text; 
                 /// <summary> 
                 /// 菜单的文字 
                 /// </summary> 
                 public  string Text 
                { 
                        get {  return _text; } 
                        set { _text = value; } 
                } 
                
                 private  string _commandButtonId; 
                 /// <summary> 
                 /// 所调用的命令按钮的ID 
                 /// </summary> 
                 public  string CommandButtonId 
                { 
                        get {  return _commandButtonId; } 
                        set { _commandButtonId = value; } 
                } 
 
                 private  string _navigateUrl; 
                 /// <summary> 
                 /// 链接的url 
                 /// </summary> 
                 public  string NavigateUrl 
                { 
                        get {  return _navigateUrl; } 
                        set { _navigateUrl = value; } 
                } 
 
                 private ItemTypeCollection _itemType; 
                 /// <summary> 
                 /// 右键菜单的项的类别 
                 /// </summary> 
                 public ItemTypeCollection ItemType 
                { 
                        get {  return _itemType; } 
                        set { _itemType = value; } 
                } 
 
                 private TargetCollection _target; 
                 /// <summary> 
                 /// 链接的target 
                 /// </summary> 
                 public TargetCollection Target 
                { 
                        get {  return _target; } 
                        set { _target = value; } 
                } 
 
 
                 /// <summary> 
                 /// 右键菜单的项的类别 
                 /// </summary> 
                 public  enum ItemTypeCollection 
                { 
                         /// <summary> 
                         /// 链接 
                         /// </summary> 
                        Link, 
                         /// <summary> 
                         /// 按钮 
                         /// </summary> 
                        Command, 
                         /// <summary> 
                         /// 分隔线 
                         /// </summary> 
                        Separator 
                } 
 
                 /// <summary> 
                 /// 链接的target 
                 /// </summary> 
                 public  enum TargetCollection 
                { 
                         /// <summary> 
                         /// 新开窗口 
                         /// </summary> 
                        Blank, 
                         /// <summary> 
                         /// 当前窗口 
                         /// </summary> 
                        Self, 
                         /// <summary> 
                         /// 跳出框架 
                         /// </summary> 
                        Top 
                } 
        } 
}
 
3、新建一个继承自CollectionBase的类ContextMenus
using System.Collections; 
using System.ComponentModel; 
using System.Web.UI; 
 
namespace YYControls.SmartGridView 

         /// <summary> 
         /// ContextMenus 的摘要说明。 
         /// 注意要继承自CollectionBase 
         /// </summary> 
        [ 
        ToolboxItem( false), 
        ParseChildren( true
        ] 
         public  class ContextMenus : CollectionBase 
        { 
                 /// <summary> 
                 /// 构造函数 
                 /// </summary> 
                 public ContextMenus() 
                        :  base() 
                { 
                } 
 
                 /// <summary> 
                 /// 实现IList接口 
                 /// 获取或设置指定索引处的元素。 
                 /// </summary> 
                 /// <param name="index">要获得或设置的元素从零开始的索引</param> 
                 /// <returns></returns> 
                 public ContextMenu  this[ int index] 
                { 
                        get 
                        { 
                                 return (ContextMenu) base.List[index]; 
                        } 
                        set 
                        { 
                                 base.List[index] = (ContextMenu)value; 
                        } 
                } 
 
                 /// <summary> 
                 /// 实现IList接口 
                 /// 将某项添加到 System.Collections.IList 中。 
                 /// </summary> 
                 /// <param name="item">要添加到 System.Collections.IList 的 System.Object。</param> 
                 public  void Add(ContextMenu item) 
                { 
                         base.List.Add(item); 
                } 
 
                 /// <summary> 
                 /// 实现IList接口 
                 /// 从 System.Collections.IList 中移除特定对象的第一个匹配项。 
                 /// </summary> 
                 /// <param name="index">要从 System.Collections.IList 移除的 System.Object</param> 
                 public  void Remove( int index) 
                { 
                         if (index > -1 && index <  base.Count) 
                        { 
                                 base.List.RemoveAt(index); 
                        } 
                } 
 
                 /// <summary> 
                 /// ToString() 
                 /// </summary> 
                 /// <returns></returns> 
                 public  override  string ToString() 
                { 
                         return  "ContextMenus"
                } 
        } 
}
 
4、在继承自GridView的类中加一个复杂对象属性,该复杂对象就是第3步创建的那个ContextMenus
private ContextMenus _contextMenus; 
                 /// <summary> 
                 /// 行的右键菜单集合 
                 /// </summary> 
                [ 
                PersistenceMode(PersistenceMode.InnerProperty), 
                DesignerSerializationVisibility(DesignerSerializationVisibility.Content), 
                Description( "行的右键菜单"), 
                Category( "扩展"
                ] 
                 public  virtual ContextMenus ContextMenus 
                { 
                        get 
                        { 
                                 if (_contextMenus ==  null
                                { 
                                        _contextMenus =  new ContextMenus(); 
                                } 
                                 return _contextMenus; 
                        } 
                }
 
 
相关文章
|
3月前
|
存储 开发框架 前端开发
在Winform分页控件中集成保存用户列表显示字段及宽度调整设置
在Winform分页控件中集成保存用户列表显示字段及宽度调整设置
|
3月前
|
开发框架 缓存 前端开发
使用扩展函数方式,在Winform界面中快捷的绑定树形列表TreeList控件和TreeListLookUpEdit控件
使用扩展函数方式,在Winform界面中快捷的绑定树形列表TreeList控件和TreeListLookUpEdit控件
|
编解码 C# 图形学
winform-SunnyUI控件解决大小位置变化
winform-SunnyUI控件解决大小位置变化
479 0
|
人工智能 C#
c#中在datagridview的表格动态增加一个按钮方法
c#中在datagridview的表格动态增加一个按钮方法,如果想要这一套教程的可以移步去这里 《期末作业C#实现学生宿舍管理系统》,对了最近我们有一个人工智能交流群,如果大家对代码有问题,想交流的可以进群,私聊我就可以了! 效果图片 : 在Load事件中写入代码 那ui有了功能怎么办呢?别急我们在 dataGridView1_CellContentClick事件中添加方法 这样的话 我们就可以点击对应行的修改来获取到id的值这里有一个bug就是第三行没数据需要隐藏,现在还没有解决,欢迎大家指出!.....
663 0
c#中在datagridview的表格动态增加一个按钮方法
|
Android开发
Android开发 ListView(垂直滚动列表项视图)的简单使用
Android开发 ListView(垂直滚动列表项视图)的简单使用
346 0
Android开发 ListView(垂直滚动列表项视图)的简单使用
|
Web App开发
艾伟:WinForm控件开发总结(七)-----为复杂属性的子属性提供编辑功能
前面的几篇文章中,我们给控件添加一个复杂的类型Scope,并且给它的类型提供的一个类型转换器,现在我们可以在属性浏览器中编辑它的值,并且它的值也被串行化的源代码里了。但是你有没有发现,在属性浏览器里编辑这个属性的值还是不太方便。
695 0