[DevExpress]DevExpress GridView 代码添加按钮

1.1 创建一个RepositoryItemButtonEdit方法

private  RepositoryItemButtonEdit CreateRepositoryItemButtonEdit(Dictionary<object, string> dicButtons)
        {
            RepositoryItemButtonEdit repositoryBtn = new RepositoryItemButtonEdit();
            repositoryBtn.AppearanceDisabled.Options.UseTextOptions = true;
            repositoryBtn.AppearanceDisabled.TextOptions.HAlignment = HorzAlignment.Near;
            repositoryBtn.AutoHeight = false;
            repositoryBtn.TextEditStyle = TextEditStyles.HideTextEditor;
            repositoryBtn.ButtonsStyle = BorderStyles.UltraFlat;
            repositoryBtn.Buttons.Clear();
            EditorButton btn = null;
            foreach (KeyValuePair<object, string> item in dicButtons)
            {
                btn = new EditorButton();
                btn.Kind = ButtonPredefines.Glyph;
                btn.Caption = item.Value;
                btn.Tag = item.Key;
                repositoryBtn.Buttons.Add(btn);
            }
            return repositoryBtn;
        }

1.2 开始调用

Dictionary<object, string> dicButtons = new Dictionary<object, string>();
            dicButtons.Add("delete", "删除");
            dicButtons.Add("download", "下载");
            RepositoryItemButtonEdit ribeFile = CreateRepositoryItemButtonEdit(dicButtons);
            //ribeFile.ButtonClick += ribeFile_ButtonClick;   //绑定事件
            gcData.RepositoryItems.Add(ribeFile);
            this.Operate.ColumnEdit = ribeFile;

效果如下:
这里写图片描述
2.另外一种方式

RepositoryItemButtonEdit rBtnEdit = new RepositoryItemButtonEdit();
            rBtnEdit.Buttons.Clear();
            rBtnEdit.TextEditStyle = TextEditStyles.DisableTextEditor;
            rBtnEdit.ButtonsStyle = BorderStyles.Default;
            rBtnEdit.Appearance.BackColor = this.ReceivableDate.AppearanceCell.BackColor;
            rBtnEdit.ButtonClick += rBtnEdit_ButtonClick;//绑定事件
            EditorButton btnSet = new EditorButton();
            btnSet.Tag = "set";
            btnSet.Kind = ButtonPredefines.Glyph;
            btnSet.ToolTip = "设置延迟日期";
            btnSet.Caption = "设置";
            rBtnEdit.Buttons.Add(btnSet);
            gcData.RepositoryItems.Add(rBtnEdit);
            this.ReceivableDate.ColumnEdit = rBtnEdit;

效果如下:
这里写图片描述
3.1 创建一个RepositoryItemPopupContainerEdit

protected virtual RepositoryItemPopupContainerEdit CreateRepositoryItemPopupContainerEdit(string caption)
        {
            RepositoryItemPopupContainerEdit repositoryPop = new RepositoryItemPopupContainerEdit();
            //repositoryCalc.AutoHeight = false;
            repositoryPop.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
            return repositoryPop;
        }

3.2 开始调用

//添加按钮
            EditorButton edit = new EditorButton();
            edit.Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Plus;
            edit.ToolTip = "添加";//提示
            edit.Tag = "add";

            RepositoryItemPopupContainerEdit ripce = CreateRepositoryItemPopupContainerEdit("标签");
            ripce.PopupControl = this.popTags;            //popupContainerControl控件
            ripce.QueryPopUp += ripce_QueryPopUp;  //弹出控制事件
            ripce.QueryResultValue += ripce_QueryResultValue;     //返回值事件
            ripce.Buttons.Add(edit);
            ripce.ButtonClick += ripce_ButtonClick;   //添加按钮事件
            gcFile.RepositoryItems.Add(ripce);
            this.TagName.ColumnEdit = ripce;   //TagName是GridView的gridColumn列

效果如下:
这里写图片描述
4.1 创建一个RepositoryItemHyperLinkEdit

protected virtual RepositoryItemHyperLinkEdit CreateRepositoryItemHyperLinkEdit(string caption)
        {
            RepositoryItemHyperLinkEdit link = new RepositoryItemHyperLinkEdit();
            link.AutoHeight = false;
            link.TextEditStyle = TextEditStyles.Standard;
            link.ReadOnly = true;
            link.SingleClick = true;
            return link;
        }

4.2 开始调用

RepositoryItemHyperLinkEdit linkSalesMoney = CreateRepositoryItemHyperLinkEdit("销售金额");
             linkSalesMoney.OpenLink += new OpenLinkEventHandler(linkSalesMoney_OpenLink);  //事件
             this.SalesMoney.ColumnEdit = linkSalesMoney;  //绑定

效果如下:
这里写图片描述

转自

阅读更多

扫码向博主提问

厦门德仔

博客专家

非学,无以致疑;非问,无以广识
  • 擅长领域:
  • ERP
  • .NET
  • SQL
  • Ext.Net
  • DevExpress
去开通我的Chat快问

没有更多推荐了,返回首页