首页 > 代码库 > DevExpress gridview 代码添加按钮

DevExpress gridview 代码添加按钮

1.1 创建一个RepositoryItemButtonEdit方法

 1  private  RepositoryItemButtonEdit CreateRepositoryItemButtonEdit(Dictionary<object, string> dicButtons)
 2         {
 3             RepositoryItemButtonEdit repositoryBtn = new RepositoryItemButtonEdit();
 4             repositoryBtn.AppearanceDisabled.Options.UseTextOptions = true;
 5             repositoryBtn.AppearanceDisabled.TextOptions.HAlignment = HorzAlignment.Near;
 6             repositoryBtn.AutoHeight = false;
 7             repositoryBtn.TextEditStyle = TextEditStyles.HideTextEditor;
 8             repositoryBtn.ButtonsStyle = BorderStyles.UltraFlat;
 9             repositoryBtn.Buttons.Clear();
10             EditorButton btn = null;
11             foreach (KeyValuePair<object, string> item in dicButtons)
12             {
13                 btn = new EditorButton();
14                 btn.Kind = ButtonPredefines.Glyph;
15                 btn.Caption = item.Value;
16                 btn.Tag = item.Key;
17                 repositoryBtn.Buttons.Add(btn);
18             }
19             return repositoryBtn;
20         }

1.2 开始调用

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

效果如下:

技术分享

 

2.另外一种方式

 1             RepositoryItemButtonEdit rBtnEdit = new RepositoryItemButtonEdit();
 2             rBtnEdit.Buttons.Clear();
 3             rBtnEdit.TextEditStyle = TextEditStyles.DisableTextEditor;
 4             rBtnEdit.ButtonsStyle = BorderStyles.Default;
 5             rBtnEdit.Appearance.BackColor = this.ReceivableDate.AppearanceCell.BackColor;
 6             rBtnEdit.ButtonClick += rBtnEdit_ButtonClick;//绑定事件
 7             EditorButton btnSet = new EditorButton();
 8             btnSet.Tag = "set";
 9             btnSet.Kind = ButtonPredefines.Glyph;
10             btnSet.ToolTip = "设置延迟日期";
11             btnSet.Caption = "设置";
12             rBtnEdit.Buttons.Add(btnSet);
13             gcData.RepositoryItems.Add(rBtnEdit);
14             this.ReceivableDate.ColumnEdit = rBtnEdit;

效果如下:

技术分享

 

3.1 创建一个RepositoryItemPopupContainerEdit

1  protected virtual RepositoryItemPopupContainerEdit CreateRepositoryItemPopupContainerEdit(string caption)
2         {
3             RepositoryItemPopupContainerEdit repositoryPop = new RepositoryItemPopupContainerEdit();
4             //repositoryCalc.AutoHeight = false;
5             repositoryPop.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
6             return repositoryPop;
7         }

3.2 开始调用

 1             //添加按钮
 2             EditorButton edit = new EditorButton();
 3             edit.Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Plus;
 4             edit.ToolTip = "添加";//提示
 5             edit.Tag = "add";
 6 
 7             RepositoryItemPopupContainerEdit ripce = CreateRepositoryItemPopupContainerEdit("标签");
 8             ripce.PopupControl = this.popTags;            //popupContainerControl控件
 9             ripce.QueryPopUp += ripce_QueryPopUp;  //弹出控制事件
10             ripce.QueryResultValue += ripce_QueryResultValue;     //返回值事件
11             ripce.Buttons.Add(edit);
12             ripce.ButtonClick += ripce_ButtonClick;   //添加按钮事件
13             gcFile.RepositoryItems.Add(ripce);
14             this.TagName.ColumnEdit = ripce;   //TagName是GridView的gridColumn列

效果如下:

技术分享

 

4.1 创建一个RepositoryItemHyperLinkEdit

1  protected virtual RepositoryItemHyperLinkEdit CreateRepositoryItemHyperLinkEdit(string caption)
2         {
3             RepositoryItemHyperLinkEdit link = new RepositoryItemHyperLinkEdit();
4             link.AutoHeight = false;
5             link.TextEditStyle = TextEditStyles.Standard;
6             link.ReadOnly = true;
7             link.SingleClick = true;
8             return link;
9         }

4.2 开始调用

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

效果如下:

技术分享

 

DevExpress gridview 代码添加按钮