[DevExpress]DevExpressGridView代码添加按钮
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;
}
.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; //绑定
效果如下:
===============
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.Office2003;
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;
}
/// <summary>
/// 为按钮注册点击事件(Click是鼠标点击)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ribCancel_ButtonClick(object sender, EventArgs e)
{
this.gdvFault.SetFocusedRowCellValue("END_TIME", DateTime.Now);
GlobalVariable.gdDtFault =(DataTable) gdcFault.DataSource;
}
BindGV()
Dictionary<object, string> dicButtons = new Dictionary<object, string>(); dicButtons.Add("close", "close");
//dicButtons.Add("download", "下载");
RepositoryItemButtonEdit ribCancel = CreateRepositoryItemButtonEdit(dicButtons);
ribCancel.ButtonClick +=new DevExpress.XtraEditors.Controls.ButtonPressedEventHandler( ribCancel_ButtonClick); //绑定事件
gdcFault.RepositoryItems.Add(ribCancel);//将控件添加到GridControl中的Items
DevGridControlHelper.BindData(gdcFault, dt, new int[] { 1, 1, 1, 1, 1});
//gdvWIPMain.Columns[0].Width = 20;
gdvFault.Columns[4].ColumnEdit = ribCancel;
以上是 [DevExpress]DevExpressGridView代码添加按钮 的全部内容, 来源链接: utcz.com/z/511336.html