1. 添加gridControl控件,添加列。假设我们这里在“操作”这一列添加按钮。
2. 打开设计器(run designer),设置“操作”列的属性。
2.1 找到ColumnEdit属性,选择“ButtonEdit”。
2.2 打开ColumnEdit属性,找到TextEditStyle属性,设置为HideTextEditor。(隐藏按钮前的文本框)
2.3 打开ColumnEdit属性,找到Buttons。点击“...”,添加Button。
2.3.1 在Collection Editor Buttons 中添加button。其中caption为名称
3. 找到ShowButtonMode属性,设置为ShowAlways
4.结果
5. 在Collection Editor Buttons中,选择空间图片时,设置ImageToTextAligment属性为LeftTop。
补充:注册事件
若想要对按钮注册事件,则需要在设计器的Repository页中的In-place Editor Repository项中在右边的Repository栏中找到你的ButtonEdit
注意:
因为这里我在一列中设置了多个ButtonEdit,所以注册事件时,只能注册一个repositoryItemButtonEdit1_ButtonClick事件。但是如果需要区分点击的是哪一个按钮,可以这样做:
private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
if (e.Button.Index == 0)
{
//新增
}
else if (e.Button.Index == 1)
{
//删除
}
else if (e.Button.Index == 2)
{
//重置
}
else
{
}
}
private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
if (e.Button.Caption == "新增")
{
}
else if (e.Button.Caption == "删除")
{
}
else if (e.Button.Caption == "重置")
{
}
else
{
}
}